#install.packages('gganimate')
#install.packages('ggcorrplot')
library(data.table)
library(ggplot2)
library(gganimate)
library(ggcorrplot)
library(plotly)
casos <- fread('https://covid.ourworldindata.org/data/owid-covid-data.csv')
Por si les interesa ver más datos de Covid-19, esta es la fuente de la información: https://ourworldindata.org/covid-cases.
casos2 <- casos[continent == 'South America']
ggplot(casos2,aes(x=date,y=new_cases,group=location,color=location)) +
geom_line()
Notamos que no se es poco entendible el gráfico, por lo cual necesitamos buscar formas de mostrar de otra forma la información.
ggplot(casos2[date >= as.Date('2021-01-01') & location != "Falkland Islands"],
aes(x=date,y=new_cases,group=location,color=location)) +
geom_line() +
facet_wrap(~location,scale='free_y',ncol=3) +
theme(legend.position = 'none')
ggplot(casos2[date >= as.Date('2021-01-01') & location != "Falkland Islands"],
aes(x=date,y=new_cases,group=location,color=location)) +
geom_line() +
geom_smooth() +
facet_wrap(~location,scale='free_y',ncol=3) +
theme_minimal() +
theme(legend.position = 'none')
ggplot(casos2[date >= as.Date('2021-01-01') & location == "Chile"],
aes(x=date,y=new_cases)) +
geom_line() +
theme(legend.position = 'none') +
theme_minimal() +
transition_reveal(date)
casos2[,prop_vacunados:=people_vaccinated/population*100]
casos2[,semana:=week(date)]
casos3 <- casos2[,.(prop_vacunados=mean(prop_vacunados,na.rm=T)),by=.(semana,location)]
ggplot(casos3[semana == 51,],
aes(x=location,y=prop_vacunados,fill=location)) +
geom_col() +
coord_flip() +
theme_minimal() +
theme(legend.position = 'none')
grafico <- ggplot(casos3[semana == 51,],
aes(x=reorder(location,prop_vacunados),y=prop_vacunados,fill=location, text=paste("Vacunados:",round(prop_vacunados,2)))) +
geom_col() +
coord_flip() +
theme_minimal() +
theme(legend.position = 'none')
ggplotly(grafico,tooltip = 'text')
vacunas3 <- casos3[semana <= 52 & location!='Falkland Islands',]
vacunas3 <- vacunas3[order(semana, -(prop_vacunados))]
vacunas3 <- vacunas3[,ranking := row.names(.SD), by=semana]
vacunas3 <- vacunas3[,ranking := as.numeric(ranking)]
animacion <- ggplot(vacunas3) +
geom_col(aes(ranking, prop_vacunados, fill = location)) +
geom_text(aes(ranking, prop_vacunados, label = prop_vacunados), hjust=-0.1) +
geom_text(aes(ranking, y=0 , label = location), hjust=1.1) +
geom_text(aes(x=12, y=max(prop_vacunados) , label = semana), vjust = 0.2, alpha = 0.5, col = "gray", size = 20) +
coord_flip(clip = "off", expand = FALSE) + scale_x_reverse() +
theme_minimal() +
labs(title = " Porcentaje de vacunados \n Semana : {closest_state}",
subtitle = "En Sudámerica",
y = "") +
theme_minimal() +
theme(panel.grid.major.x = element_blank(),
plot.title = element_text(size = 18,
face = "bold",
hjust = 0.5),
plot.subtitle = element_text(size=14,
face = "plain",
hjust = 0.5)) +
theme(
panel.grid = element_blank(),
legend.position = "none",
axis.ticks.y = element_blank(),
axis.title.y = element_blank(),
axis.text.y = element_blank(),
plot.margin = margin(1, 4, 1, 3, "cm")
) +
transition_states(semana, state_length = 0, transition_length = 2) +
enter_fade() +
exit_fade() +
ease_aes('quadratic-in-out')
ani <- animate(animacion, nframes= 300, width = 600, height = 600, fps = 10)