Importar datos y generar estadisticas diarias

Datos son tomados de Organización Mundial de la salud

# importar el dataset
covidData <- read.csv("~/Desktop/Univalle2022/Covid_exercise/CovidNew/WHO-COVID-19-global-data.csv", stringsAsFactors=TRUE)

covidData$Date_reported <- as.Date(covidData$Date_reported)

str(covidData)
## 'data.frame':    210219 obs. of  8 variables:
##  $ Date_reported    : Date, format: "2020-01-03" "2020-01-04" ...
##  $ Country_code     : Factor w/ 236 levels " ","AD","AE",..: 4 4 4 4 4 4 4 4 4 4 ...
##  $ Country          : Factor w/ 237 levels "Afghanistan",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ WHO_region       : Factor w/ 7 levels "AFRO","AMRO",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ New_cases        : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Cumulative_cases : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ New_deaths       : int  0 0 0 0 0 0 0 0 0 0 ...
##  $ Cumulative_deaths: int  0 0 0 0 0 0 0 0 0 0 ...
library(ggplot2)
library(ggThemeAssist)

# Casos diarios
grafica <- ggplot(covidData)
grafica <- grafica + aes(x=covidData$Date_reported, y=covidData$New_cases)
grafica <- grafica + geom_col()
grafica <- grafica + labs(title = "Covid 19 Reporte Global Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos casos de contagio")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
## Warning: Use of `covidData$Date_reported` is discouraged. Use `Date_reported`
## instead.
## Warning: Use of `covidData$New_cases` is discouraged. Use `New_cases` instead.

# muertes diarias
grafica <- ggplot(covidData)
grafica <- grafica + aes(x=covidData$Date_reported, y=covidData$New_deaths)
grafica <- grafica + geom_col()
grafica <- grafica + labs(title = "Covid 19 Reporte Global Junio 2022", x = "Fecha", y = "Nuevas  muertes", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevas muertes diarias")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
## Warning: Use of `covidData$Date_reported` is discouraged. Use `Date_reported`
## instead.
## Warning: Use of `covidData$New_deaths` is discouraged. Use `New_deaths` instead.

Por zonas del mundo

# Casos diarios por zonas
grafica <- ggplot(covidData)
grafica <- grafica + aes(x=covidData$Date_reported, y=covidData$New_cases, fill=WHO_region)
grafica <- grafica + geom_col()
grafica <- grafica + labs(title = "Covid 19 Reporte Global Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos casos de contagio")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
## Warning: Use of `covidData$Date_reported` is discouraged. Use `Date_reported`
## instead.
## Warning: Use of `covidData$New_cases` is discouraged. Use `New_cases` instead.

# Casos diarios por zonas discriminadas
grafica <- ggplot(covidData)
grafica <- grafica + aes(x=covidData$Date_reported, y=covidData$New_cases, fill=WHO_region)
grafica <- grafica + geom_col()
grafica <- grafica + labs(title = "Covid 19 Reporte Global Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos casos de contagio")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica <- grafica + facet_wrap(covidData$WHO_region) 
grafica <- grafica + theme(axis.text.x = element_text(angle = 90, size=7))
grafica
## Warning: Use of `covidData$Date_reported` is discouraged. Use `Date_reported` instead.
## Use of `covidData$New_cases` is discouraged. Use `New_cases` instead.

# Grafica de barras
covidTable <- read.csv("~/Desktop/Univalle2022/Covid_exercise/CovidNew/WHO-COVID-19-global-table-data.csv", stringsAsFactors=TRUE)

str(covidTable)
## 'data.frame':    238 obs. of  12 variables:
##  $ Name                                                        : Factor w/ 8 levels "","Africa","Americas",..: 1 3 7 3 5 5 5 5 3 3 ...
##  $ WHO.Region                                                  : int  199466211 35010407 31769132 19953501 6356784 6039483 5923824 5795665 4947030 4801050 ...
##  $ Cases...cumulative.total                                    : num  2559 10577 2302 9387 4356 ...
##  $ Cases...cumulative.total.per.100000.population              : int  4158340 618994 284527 245839 161552 139087 178294 157487 87860 64701 ...
##  $ Cases...newly.reported.in.last.7.days                       : num  53.3 187 20.6 115.7 110.7 ...
##  $ Cases...newly.reported.in.last.7.days.per.100000.population : int  548167 78722 42625 15143 22589 25481 21466 24832 11183 6636 ...
##  $ Cases...newly.reported.in.last.24.hours                     : int  4244541 609022 425757 557223 161715 110921 129881 51645 106045 121216 ...
##  $ Deaths...cumulative.total                                   : num  54.5 184 30.9 262.1 110.8 ...
##  $ Deaths...cumulative.total.per.100000.population             : int  64036 2759 3735 6721 5537 239 578 597 1940 2034 ...
##  $ Deaths...newly.reported.in.last.7.days                      : num  0.822 0.83 0.27 3.16 3.79 ...
##  $ Deaths...newly.reported.in.last.7.days.per.100000.population: int  8430 387 562 389 790 62 138 126 273 218 ...
##  $ Deaths...newly.reported.in.last.24.hours                    : logi  NA NA NA NA NA NA ...
#install.packages("dplyr")

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
regiones <- covidTable %>% group_by(Name) %>% summarize(Total = sum(WHO.Region))
regiones <- regiones[-1,]

grafica <- ggplot(regiones) + aes(y= reorder(Name,Total), x=Total, fill=Name) + geom_col() + labs(title = "Regiones Covid")
grafica

Bulgaria

bulgaria <- filter(covidData, Country=='Bulgaria')

grafica <- ggplot(bulgaria)
grafica <- grafica + aes(x=bulgaria$Date_reported, y=bulgaria$New_cases)
grafica <- grafica + geom_col(aes(alpha=0.3))
grafica <- grafica + geom_smooth(span=0.02)
grafica <- grafica + labs(title = "Covid 19 Reporte Bulgaria Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos casos de contagio")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
## Warning: Use of `bulgaria$Date_reported` is discouraged. Use `Date_reported`
## instead.
## Warning: Use of `bulgaria$New_cases` is discouraged. Use `New_cases` instead.
## Warning: Use of `bulgaria$Date_reported` is discouraged. Use `Date_reported`
## instead.
## Warning: Use of `bulgaria$New_cases` is discouraged. Use `New_cases` instead.
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'