|
cran_packages <- c("reshape2","ggplot2") |
|
if (length(setdiff(cran_packages, rownames(installed.packages()))) > 0) { |
|
install.packages(setdiff(cran_packages, rownames(installed.packages())), dependencies=TRUE, repos='http://cran.rstudio.com/') |
|
} |
|
library(reshape2) |
|
library(ggplot2) |
|
|
|
primer_brote <- "2020-02-14" |
|
brote_dif <- 9 |
|
|
|
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv" |
|
cvirus <- read.table(url, sep = ",", header = T) |
|
|
|
cvirus$Lat <- cvirus$Long <- NULL |
|
cvirus$Province.State <- NULL |
|
cvirus <- melt(cvirus, id.vars = "Country.Region") |
|
colnames(cvirus) <- c("país", "fecha", "casos") |
|
cvirus$casos <- as.numeric(cvirus$casos) |
|
cvirus <- cvirus[cvirus$país %in% c("Italy", "Spain"),] |
|
cvirus$fecha <- as.Date(as.character(cvirus$fecha), format = "X%m.%d.%y") |
|
|
|
|
|
|
|
tmp <- cvirus |
|
tmp$fecha[tmp$país == "Spain"] <- tmp$fecha[tmp$país == "Spain"] - brote_dif |
|
tmp$dias_desde_brote <- as.numeric(as.Date(tmp$fecha)-as.Date(primer_brote)) |
|
tmp <- tmp[tmp$fecha > as.Date(primer_brote),] |
|
|
|
ggplot(tmp, aes(x = dias_desde_brote, y = casos, col = país)) + geom_line() + |
|
scale_x_continuous(breaks = seq(from = 0, to=365, by = 2)) + |
|
scale_y_continuous(breaks = seq(from = 0, to=400000000, by = 2000)) + |
|
xlab("días desde el brote")+ |
|
labs( |
|
title=paste0("Brote Coronavirus: Italia ",primer_brote," vs España ",as.character(as.Date(primer_brote)+brote_dif)), |
|
caption=paste0("Generado ",Sys.Date()) |
|
) |
|
|
|
ggsave("R/data/coronavirus-italy-spain.png", width = 29, height = 21, units = "cm") |