Skip to content

Instantly share code, notes, and snippets.

@jrosell
Created March 12, 2020 10:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrosell/bfd41d96068827761dc72520cf890dc5 to your computer and use it in GitHub Desktop.
Save jrosell/bfd41d96068827761dc72520cf890dc5 to your computer and use it in GitHub Desktop.
Brote coranovirus Italia vs España 2020. Modificación de desarrollo inicial @cjgb, que compartió código y datos en https://www.datanalytics.com/2020/03/09/seguimiento-del-coronavirus-en-tiempo-real-con-r/
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")
@jrosell
Copy link
Author

jrosell commented Mar 12, 2020

coronavirus-italy-spain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment