library(pacman)
p_load("base64enc", "htmltools", "mime", "xfun", "prettydoc", "readr", "knitr", "DT", "tidyverse", "scales", "gridExtra", "modeest", "fdth", "gganimate", "gifski", "plotly")
SONORA <- read_csv("SONORA.csv")## Parsed with column specification:
## cols(
## country_region_code = col_character(),
## country_region = col_character(),
## sub_region_1 = col_character(),
## sub_region_2 = col_logical(),
## metro_area = col_logical(),
## iso_3166_2_code = col_character(),
## census_fips_code = col_logical(),
## date = col_character(),
## retail_and_recreation_percent_change_from_baseline = col_double(),
## grocery_and_pharmacy_percent_change_from_baseline = col_double(),
## parks_percent_change_from_baseline = col_double(),
## transit_stations_percent_change_from_baseline = col_double(),
## workplaces_percent_change_from_baseline = col_double(),
## residential_percent_change_from_baseline = col_double()
## )
Filtrado de datos y creacion de data frame
FechaMR <- seq(from = as.Date("2020-02-15"), to= as.Date("2020-10-13"), by = 'day')
RRP <- SONORA$retail_and_recreation_percent_change_from_baseline
GPP <- SONORA$grocery_and_pharmacy_percent_change_from_baseline
PP <- SONORA$parks_percent_change_from_baseline
TP <- SONORA$transit_stations_percent_change_from_baseline
WP <- SONORA$workplaces_percent_change_from_baseline
RP <- SONORA$residential_percent_change_from_baseline
Datos <- data.frame(x=FechaMR,y=RRP)Gráficas
gRR <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=RRP), size=1, colour="purple") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("a) Comercio y recreación (-45%)")
gGP <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=GPP), size=1, colour="brown") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("b) Farmacias y abarrotes (-11%)")
gP <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=PP), size=1, colour="blue") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("c) Parques (-37%)")
gT <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=TP), size=1, colour="green") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("d) Estaciones de tránsito (-43%)")
gW <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=WP), size=1, colour="red") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("e) Espacios de trabajo (-37%)")
gR <- ggplot(data=Datos) +
geom_line(aes(x=FechaMR, y=RP), size=1, colour="black") +
geom_hline(yintercept = 0) +
theme_light() +
xlab("Fecha") +
ylab("Porcentaje") +
ggtitle("f) Hogares (+18%)")
p_load(gridExtra)
grid.arrange(gRR, gGP, gP, gT, gW, gR)Datos2 <- data.frame(FechaMR, RRP, GPP, PP, TP, WP, RP)
gP <- ggplot(data = Datos2)+
geom_line(aes(x=FechaMR, y=RRP), colour="purple") +
geom_line(aes(x=FechaMR, y=GPP), colour="brown") +
geom_line(aes(x=FechaMR, y=PP), colour="blue") +
geom_line(aes(x=FechaMR, y=TP), colour="green") +
geom_line(aes(x=FechaMR, y=WP), colour="red") +
geom_line(aes(x=FechaMR, y=RP), colour="black") +
ggtitle("Porcentaje de Comportamiento de personas después del inicio de la cuaretena") + xlab("Fecha") +
ylab("Porcentajes")+transition_reveal(FechaMR)
ggplotly(gP)Moda, Media y Mediana de porcentaje de comercio y recreación
## [1] -31
## [1] -38.07025
## [1] -41
Moda, Media y Mediana de porcentaje de farmacias y abarrotes
## [1] -13
## [1] -13.31405
## [1] -14
Moda, Media y Mediana de porcentaje de parques
## [1] -38
## [1] -31.4876
## [1] -34
Moda, Media y Mediana de porcentaje de estaciones de tránsito
## [1] -29
## [1] -36.21074
## [1] -39
Moda, Media y Mediana de porcentaje de espacios de trabajo
## [1] -40
## [1] -28.47521
## [1] -34
Moda, Media y Mediana de porcentaje de Hogares
## [1] 13
## [1] 13.13636
## [1] 14