This notebook shows the codes and how animated charts of the growth of cases and deaths by COVID-19 in the USA by State were created between the months of 01/21/2020 to 03/04/2020. The database used on this notebook can be found here.

Este notebook mostra os códigos e como foram criados os gráficos animados do crescimento de casos e mortes por COVID-19 nos EUA por Estado entre os meses de 21/01/2020 até 03/04/2020. O banco de dados utilizado nesse notebook pode ser encontrado aqui.

Import packages / Importando pacotes

library(transformr)
library(dplyr)
library(gapminder)
library(gganimate)
library(ggplot2)
library(dplyr)
require(maps)

Import data / Importando os dados

data <- read.csv("us-counties.csv")
data$date <- as.Date(data$date)
data <- data[order(data$date),]

Number of cases per COVID-19 / Número de casos por COVID-19

dataUSA <- data  %>% group_by(state,date) %>% summarise(nCasos = sum(cases))
dataUSA$region <- tolower(dataUSA$state)
states_map <- map_data("state")
arrests_map <- left_join(states_map, dataUSA, by = "region")

a <- ggplot(arrests_map, aes(long, lat, group = group,fill = nCasos))+
      #scale_colour_manual(colour = nCasos) +
      geom_polygon(color = "white")+
      labs(title = 'Number of cases COVID-19: {frame_time}')  + 
      scale_fill_gradient(trans = "log10",low = "blue",high = "orange",breaks=c(1,100,1000,5000,15000,50000)) +
      transition_time(date)

anim = animate(a)
anim_save("a.gif", anim)

Number of deaths per COVID-19 / Número de mortes por COVID-19

dataUSA <- data  %>% group_by(state,date) %>% summarise(nMortes = sum(deaths))
dataUSA$region <- tolower(dataUSA$state)
states_map <- map_data("state")
arrests_map <- left_join(states_map, dataUSA, by = "region")

b <- ggplot(arrests_map, aes(long, lat, group = group,fill = nMortes))+
  #scale_colour_manual(colour = nCasos) +
  geom_polygon(color = "white")+
  labs(title = 'Number of deaths COVID-19: {frame_time}')  + 
  scale_fill_gradient(trans = "log10",low = "blue",high = "orange",breaks=c(1,100,1000,5000)) +
  transition_time(date)

anim = animate(b)
anim_save("b.gif", anim)


That's all folks!