Para esto, utilizamos datos de la universidad Johns Hopkins
library(readr) #leer datos
library(plotly) #graficos interactivos
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(tidyverse) #ciencia de datos
## -- Attaching packages ------------------------------------------- tidyverse 1.3.0 --
## v tibble 3.0.3 v dplyr 1.0.2
## v tidyr 1.1.1 v stringr 1.4.0
## v purrr 0.3.4 v forcats 0.5.0
## -- Conflicts ---------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::lag() masks stats::lag()
library(gganimate) #animaciones grƔficas
library(gifski) #fabricar GIF
url_conf <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
url_decesos <-"https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_deaths_global.csv"
url_recuperados <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_recovered_global.csv"
datos_conf <- read.csv(url_conf)
datos_decesos <- read.csv(url_decesos)
datos_recuperados<- read.csv(url_recuperados)
conf_mex <- t(datos_conf[datos_conf$Country.Region =="Mexico" ,])
dec_mex <- t(datos_decesos[datos_decesos$Country.Region =="Mexico" ,])
rec_mex <- t(datos_recuperados[datos_recuperados$Country.Region =="Mexico" ,])
plot(conf_mex)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción
plot(dec_mex)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción
# Elaborar vector de fechas
Fecha <- seq(from = as.Date("2020-01-22"), to = as.Date("2020-09-03"), by="day")
#transformacion de datos a vectores
#confirmados
vec1 <- as.vector(conf_mex)
vec2 <- vec1[5:230]
num1 <- as.numeric(vec2)
confirmados <- as.vector(num1)
#decesos
vec1 <- as.vector(dec_mex)
vec2 <- vec1[5:230]
num1 <- as.numeric(vec2)
Decesos <- as.vector(num1)
#recuperados
vec1 <- as.vector(rec_mex)
vec2 <- vec1[5:230]
num1 <- as.numeric(vec2)
Recuperados <- as.vector(num1)
#ordenar los datos gata frame
datos1 <- data.frame(Fecha, confirmados, Decesos, Recuperados)
ggplot(data = datos1) +
geom_line(mapping = aes(x= Fecha, y = confirmados))