#Importar datos y generar estadísticas diarias
Datos son tomados de la Organización Mundial de la Salud
#Importat el dataset
covidData <- read.csv("C:/Users/julia/OneDrive/Desktop/Maestria/Semestre 1/Visualizacion de datos/Ejercicios clase 2/Clase 2/WHO-COVID-19-global-data.csv", stringsAsFactors=TRUE) #String como factores para agrupar la info en categorías
covidData$ï..Date_reported <- as.Date(covidData$ï..Date_reported)
#Para pasar y tipo fecha
str(covidData) #Muestra la estructura de la tabla
## '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) + aes(x=ï..Date_reported, y=New_cases) + geom_col()
#grafica <- grafica + geom_line() aes corresponde a estética
grafica <- grafica+labs(title = "Covid 19 Reporte Junio 2022",
x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organización Mundial de la Salud",subtitle = "Nuevos casos de contagio")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
#date_breaks muestra cada cuánto generar guía en el eje en la gráfica
grafica
#Muertes diarias
grafica <- ggplot(covidData) + aes(x=ï..Date_reported, y=New_deaths) + geom_col()
grafica <- grafica+labs(title = "Covid 19 Reporte Junio 2022", x = "Fecha", y = "Nuevas muertes", caption = "Datos tomados de la Organización Mundial de la Salud",subtitle = "Nuevas muertes")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
#Casos diarios porzonas
grafica <- ggplot(covidData) + aes(x=ï..Date_reported, y=New_cases, fill=WHO_region)
#fill corresponde al relleno por categoría del mismo color y color al contorno
grafica <- grafica + geom_col()
grafica <- grafica+labs(title = "Covid 19 Reporte Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organización Mundial de la Salud",subtitle = "Nuevos casos de contagio por zonas")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
#Casos diarios por zonas discriminadas
grafica <- ggplot(covidData) + aes(x=ï..Date_reported, y=New_cases, fill=WHO_region)
grafica <- grafica + geom_col() #geom_col es geometría de columnas
grafica <- grafica+labs(title = "Covid 19 Reporte Junio 2022", x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organización Mundial de la Salud",subtitle = "Nuevos casos de contagio por zonas discriminadas")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica <- grafica + facet_wrap(covidData$WHO_region) #Crea faceta por vble categórica
grafica <- grafica + theme(axis.text.x = element_text(angle=90, size=7))
#theme corresponde a visualización del gráfico y varia el ángulo y tamaño de la letra
grafica
#Grafica de barras
covidTable <- read.csv("C:/Users/julia/OneDrive/Desktop/Maestria/Semestre 1/Visualizacion de datos/Ejercicios clase 2/Clase 2/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 ...
View(covidTable)
#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) %>% summarise(Total=sum(WHO.Region))
#significa que tome un archivo y apliquele una función (por libreria dplyr)
regiones <- regiones[-1,]
grafica <- ggplot(regiones) + aes(y=reorder(ï..Name,Total), x=Total, fill=ï..Name)
grafica <- grafica + geom_col() + labs(title = "Regiones Covid")
grafica
bulgaria <- filter(covidData, Country=='Bulgaria')
grafica <- ggplot(bulgaria) + aes(x=ï..Date_reported, y=New_cases)
grafica <- grafica + geom_col(aes(alpha=0.3)) #alpha es transparencia
grafica <- grafica + geom_smooth(span=0.01)
#smooth es la linea suavizada y span es ajuste a gráfico, entre menor, más ajuste
grafica <- grafica+labs(title = "Covid 19 Reporte Junio 2022",
x = "Fecha", y = "Nuevos casos", caption = "Datos tomados de la Organización Mundial de la Salud",subtitle = "Nuevos casos de Bulgaria")
grafica <- grafica + scale_x_date(date_breaks = "16 weeks")
grafica
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : k-d tree limited by memory. ncmax= 887
## Warning in predLoess(object$y, object$x, newx = if
## (is.null(newdata)) object$x else if (is.data.frame(newdata))
## as.matrix(model.frame(delete.response(terms(object)), : k-d tree limited by
## memory. ncmax= 887