Importar Datos y Generar estadisticas diarias
Datos son tomados de Organización Mundial de la Salud
##importar el dataset
CovidData <- read.csv("~/Maestria/Visialización de datos/CovidNew/WHO-COVID-19-global-data.csv", stringsAsFactors=TRUE)
str(CovidData)
## 'data.frame': 210219 obs. of 8 variables:
## $ ï..Date_reported : Factor w/ 887 levels "2020-01-03","2020-01-04",..: 1 2 3 4 5 6 7 8 9 10 ...
## $ 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 ...
##Se observa que la primera columna es de tipo factor, se convierte a tipo datetime por ser fecha.
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) #Lienzo para iniciar gráfica
grafica<-grafica + aes(x=ï..Date_reported,y=New_cases) #creando las coordenadas
grafica<-grafica + geom_col() #gráfico en columnas.
grafica<-grafica+ geom_line()
grafica+labs(title = "Covid 10 Reporte Global Junio 2022",
x = "Fecha", y = "Nuevos Casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos de contagio ")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
#Muertes diarias
grafica<-ggplot(CovidData)
grafica<-grafica + aes(x=CovidData$ï..Date_reported,y=CovidData$New_deaths)
grafica<-grafica + geom_col() #gráfico en columnas.
grafica<-grafica+ geom_line()
grafica+labs(title = "Covid 10 Reporte Global Junio 2022",
x = "Fecha", y = "Nuevas muertes", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos de contagio ")
## Warning: Use of `CovidData$ï..Date_reported` is discouraged. Use
## `ï..Date_reported` instead.
## Warning: Use of `CovidData$New_deaths` is discouraged. Use `New_deaths` instead.
## 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=ï..Date_reported,y=New_cases,fill=WHO_region)
grafica<-grafica + geom_col()
grafica<-grafica+ geom_line()
grafica+labs(title = "Covid 10 Reporte Global Junio 2022",
x = "Fecha", y = "Nuevos Casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos de contagio ")
grafica
#Casos diarios por zonas discriminadas
grafica<-ggplot(CovidData)
grafica<-grafica + aes(x=ï..Date_reported,y=New_cases,fill=WHO_region)
grafica<-grafica + geom_col()
grafica<-grafica+ geom_line()
grafica+labs(title = "Covid 10 Reporte Global Junio 2022",
x = "Fecha", y = "Nuevos Casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos de contagio ")
grafica <-grafica + facet_wrap(CovidData$WHO_region)
grafica
#Casos diarios por zonas discriminadas
grafica<-ggplot(CovidData)
grafica<-grafica + aes(x=ï..Date_reported,y=New_cases,fill=WHO_region)
grafica<-grafica + geom_col()
grafica<-grafica+ geom_line()
grafica+labs(title = "Covid 10 Reporte Global Junio 2022",
x = "Fecha", y = "Nuevos Casos", caption = "Datos tomados de la Organizacion Mundial de la Salud", subtitle = "Nuevos de contagio ")
grafica <-grafica + facet_wrap(CovidData$WHO_region)
#grafica <-grafica + theme(axis.text.x=element_tex(angle=90, size=7))
grafica
#Grafica de barras
CovidTable <-read.csv("~/Maestria/Visialización de datos/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,fill=WHO_region)
grafica<-grafica + geom_col(aes(alpha=0.3))
grafica<- grafica + geom_smooth(span=0.02)
grafica<-grafica+ geom_line()
grafica<- grafica +labs(title = "Covid 10 Reporte Global Junio 2022", x = "Fecha", y = "Nuevos Casos", caption = "Covid 19 Reporte Bulgaria 2022", subtitle = "Nuevos de contagio ")
grafica<- grafica + scale_x_date(date_breaks = "16 weeks")
#grafica