#install.packages("maps")
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.6.3
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.0     v purrr   0.3.3
## v tibble  2.1.3     v dplyr   0.8.4
## v tidyr   1.0.2     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.5.0
## Warning: package 'tidyr' was built under R version 3.6.3
## Warning: package 'readr' was built under R version 3.6.3
## Warning: package 'purrr' was built under R version 3.6.3
## Warning: package 'dplyr' was built under R version 3.6.3
## Warning: package 'stringr' was built under R version 3.6.3
## Warning: package 'forcats' was built under R version 3.6.3
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(lubridate)
## Warning: package 'lubridate' was built under R version 3.6.3
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
library(maps)
## Warning: package 'maps' was built under R version 3.6.3
## 
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
## 
##     map
confirmados <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv")

recuperados <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv")

muertos <- read.csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv")
names(confirmados)
##   [1] "Province.State" "Country.Region" "Lat"            "Long"          
##   [5] "X1.22.20"       "X1.23.20"       "X1.24.20"       "X1.25.20"      
##   [9] "X1.26.20"       "X1.27.20"       "X1.28.20"       "X1.29.20"      
##  [13] "X1.30.20"       "X1.31.20"       "X2.1.20"        "X2.2.20"       
##  [17] "X2.3.20"        "X2.4.20"        "X2.5.20"        "X2.6.20"       
##  [21] "X2.7.20"        "X2.8.20"        "X2.9.20"        "X2.10.20"      
##  [25] "X2.11.20"       "X2.12.20"       "X2.13.20"       "X2.14.20"      
##  [29] "X2.15.20"       "X2.16.20"       "X2.17.20"       "X2.18.20"      
##  [33] "X2.19.20"       "X2.20.20"       "X2.21.20"       "X2.22.20"      
##  [37] "X2.23.20"       "X2.24.20"       "X2.25.20"       "X2.26.20"      
##  [41] "X2.27.20"       "X2.28.20"       "X2.29.20"       "X3.1.20"       
##  [45] "X3.2.20"        "X3.3.20"        "X3.4.20"        "X3.5.20"       
##  [49] "X3.6.20"        "X3.7.20"        "X3.8.20"        "X3.9.20"       
##  [53] "X3.10.20"       "X3.11.20"       "X3.12.20"       "X3.13.20"      
##  [57] "X3.14.20"       "X3.15.20"       "X3.16.20"       "X3.17.20"      
##  [61] "X3.18.20"       "X3.19.20"       "X3.20.20"       "X3.21.20"      
##  [65] "X3.22.20"       "X3.23.20"       "X3.24.20"       "X3.25.20"      
##  [69] "X3.26.20"       "X3.27.20"       "X3.28.20"       "X3.29.20"      
##  [73] "X3.30.20"       "X3.31.20"       "X4.1.20"        "X4.2.20"       
##  [77] "X4.3.20"        "X4.4.20"        "X4.5.20"        "X4.6.20"       
##  [81] "X4.7.20"        "X4.8.20"        "X4.9.20"        "X4.10.20"      
##  [85] "X4.11.20"       "X4.12.20"       "X4.13.20"       "X4.14.20"      
##  [89] "X4.15.20"       "X4.16.20"       "X4.17.20"       "X4.18.20"      
##  [93] "X4.19.20"       "X4.20.20"       "X4.21.20"       "X4.22.20"      
##  [97] "X4.23.20"       "X4.24.20"       "X4.25.20"       "X4.26.20"      
## [101] "X4.27.20"       "X4.28.20"       "X4.29.20"       "X4.30.20"      
## [105] "X5.1.20"        "X5.2.20"        "X5.3.20"        "X5.4.20"       
## [109] "X5.5.20"        "X5.6.20"        "X5.7.20"        "X5.8.20"       
## [113] "X5.9.20"        "X5.10.20"       "X5.11.20"       "X5.12.20"      
## [117] "X5.13.20"       "X5.14.20"       "X5.15.20"       "X5.16.20"      
## [121] "X5.17.20"       "X5.18.20"       "X5.19.20"       "X5.20.20"      
## [125] "X5.21.20"       "X5.22.20"       "X5.23.20"       "X5.24.20"      
## [129] "X5.25.20"       "X5.26.20"       "X5.27.20"       "X5.28.20"      
## [133] "X5.29.20"       "X5.30.20"
head(confirmados$Country.Region)
## [1] Afghanistan         Albania             Algeria            
## [4] Andorra             Angola              Antigua and Barbuda
## 188 Levels: Afghanistan Albania Algeria Andorra Angola ... Zimbabwe
covid19 <- mutate(confirmados, Category = "Confirmed") %>%
bind_rows(mutate(recuperados, Category = "Recovered")) %>%
bind_rows(mutate(muertos, Category = "Deaths")) %>%
select(Province.State:Long, Category, everything()) %>%
pivot_longer(-(Province.State:Category), names_to = "Date", values_to = "Value") %>%
mutate(Date = mdy(str_remove(Date, "X")))
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Warning in bind_rows_(x, .id): binding character and factor vector, coercing
## into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector, coercing
## into character vector

## Warning in bind_rows_(x, .id): binding character and factor vector, coercing
## into character vector
covid19 <- covid19 %>%
filter(!is.na(Value))
covid19 %>%
filter(Date == ymd("2020 03 01")) %>%
head
## # A tibble: 6 x 7
##   Province.State Country.Region        Lat   Long Category  Date       Value
##   <chr>          <fct>               <dbl>  <dbl> <chr>     <date>     <int>
## 1 ""             Afghanistan          33    65    Confirmed 2020-03-01     1
## 2 ""             Albania              41.2  20.2  Confirmed 2020-03-01     0
## 3 ""             Algeria              28.0   1.66 Confirmed 2020-03-01     1
## 4 ""             Andorra              42.5   1.52 Confirmed 2020-03-01     0
## 5 ""             Angola              -11.2  17.9  Confirmed 2020-03-01     0
## 6 ""             Antigua and Barbuda  17.1 -61.8  Confirmed 2020-03-01     0
covid19 %>%
filter(Date == max(Date),   
Country.Region == "Peru" ) %>%
head
## # A tibble: 3 x 7
##   Province.State Country.Region   Lat  Long Category  Date        Value
##   <chr>          <fct>          <dbl> <dbl> <chr>     <date>      <int>
## 1 ""             Peru           -9.19 -75.0 Confirmed 2020-05-30 155671
## 2 ""             Peru           -9.19 -75.0 Recovered 2020-05-30  66447
## 3 ""             Peru           -9.19 -75.0 Deaths    2020-05-30   4371
options(scipen = 20)
paises_a_comparar <- c("Argentina", "Brazil", "Chile", "Uruguay", "Peru", "Paraguay", "Bolivia", "Colombia", "Venezuela", "Ecuador" )
covid19 %>%
filter(Country.Region %in% paises_a_comparar) %>%
group_by(Category, Date, Country.Region) %>%
summarise(Value = sum(Value)) %>%
ggplot() +
geom_col(aes(x = Date, y = Value, fill = Category)) + 
facet_wrap(~Country.Region, scales = "free") +
scale_fill_brewer(palette = "Set2") +
labs(title = "COVID19: Cantidad de casos", subtitle = paste("al", max(covid19$Date)),
fill = "Situación",
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE",
y = NULL, x = NULL) +
theme_light()

covid19 %>%
filter(Country.Region %in% paises_a_comparar, Category == "Confirmed") %>%
group_by(Date, Country.Region) %>%
summarise(Value = sum(Value)) %>%
ggplot() +
geom_col(aes(x = Country.Region, y = Value)) +
coord_flip()+
labs(title = "COVID19: Confirmados | América del Sur" , subtitle = paste("al", max(covid19$Date)),
color = "",
x = NULL, y = NULL,
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE") +
theme_light()

covid19 %>%
filter(Country.Region %in% paises_a_comparar, Category == "Confirmed") %>%
group_by(Date, Country.Region) %>%
summarise(Value = sum(Value)) %>%
ggplot() +
geom_path(aes(x = Date, y = Value, color = Country.Region)) +
scale_y_log10() +
labs(title = "COVID19: Confirmados | América del Sur" , subtitle = paste("al", max(covid19$Date)),
color = "",
x = NULL, y = NULL,
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE") +
theme_light()
## Warning: Transformation introduced infinite values in continuous y-axis

covid19 %>%
filter(Country.Region %in% paises_a_comparar, Category == "Recovered") %>%
group_by(Date, Country.Region) %>%
summarise(Value = sum(Value)) %>%
ggplot() +
geom_path(aes(x = Date, y = Value, color = Country.Region)) +
scale_y_log10() +
labs(title = "COVID19: Recuperados | América del Sur" , subtitle = paste("al", max(covid19$Date)),
color = "",
x = NULL, y = NULL,
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE") +
theme_light()
## Warning: Transformation introduced infinite values in continuous y-axis

covid19 %>%
filter(Country.Region %in% paises_a_comparar, Category == "Deaths") %>%
group_by(Date, Country.Region) %>%
summarise(Value = sum(Value)) %>%
ggplot() +
geom_path(aes(x = Date, y = Value, color = Country.Region)) +
scale_y_log10() +
labs(title = "COVID19: Fallecidos | América del Sur", subtitle = paste("al", max(covid19$Date)),
color = "",
x = NULL, y = NULL,
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE") +
theme_light()
## Warning: Transformation introduced infinite values in continuous y-axis

ggplot() +
geom_polygon(data = map_data("world"),
aes(x = long, y = lat, group = group),
fill="gray90", colour = "white") +
# Retiramos los lugares donde el conteo aún es 0
geom_point(data = filter(covid19, Date == max(Date), Category == "Confirmed", Value > 0),
aes(x = Long, y = Lat, size = Value),
alpha = .5, color = "salmon") +
# Usamos escala logarítmica
scale_size(trans = "log10") +
labs(title = "COVID19: Infecciones confirmadas",
subtitle = paste("al", max(covid19$Date)),
caption = "Fuente: 2019 Novel Coronavirus COVID-19 Data Repository by Johns Hopkins CSSE", x="Longitud" , y="Latitud") +
theme_light()