library(readr) #leer archivos
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) #paquete de 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) #animar graficas
library(gifski) #Hacer GIF'S
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_chl <- t(datos_conf [datos_conf$Country.Region=="Chile" ,])
dec_chl <- t(datos_decesos [datos_decesos$Country.Region=="Chile" ,])
rec_chl <- t(datos_recuperados [datos_recuperados$Country.Region=="Chile" ,])
##Ordenar y transformar primeras graficas para reconocimiento
plot(conf_chl)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción
plot(dec_chl)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción
plot(rec_chl)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción
Fecha <- seq(from = as.Date("2020-01-22"), to =as.Date("2020-09-03"), by = "day") #Ordena de tu propia maera el eje x de la tabla (Segun fechas en este caso), creando un vector de fechas
#Datos transformados a vectores numéricos
#Confirmados
vec1 <- as.vector(conf_chl) # Transformacion de lista a vector
vec2 <- vec1[5:230] #filtrado de los primeros 4 valores
num1 <- as.numeric(vec2)#Transformacion a datos numericos
Confirmados <- as.vector(num1)#Vector numerico
#Recuperados
vec1 <- as.vector(rec_chl) # Transformacion de lista a vector
vec2 <- vec1[5:230] #filtrado de los primeros 4 valores
num1 <- as.numeric(vec2)#Transformacion a datos numericos
Recuperados <- as.vector(num1)#Vector numerico
#Decesos
vec1 <- as.vector(dec_chl) # Transformacion de lista a vector
vec2 <- vec1[5:230] #filtrado de los primeros 4 valores
num1 <- as.numeric(vec2)#Transformacion a datos numericos
Decesos <- as.vector(num1)#Vector numerico
*Asignacion de los data Frame
#Asignacion de un data frame
datos1 <- data.frame(Fecha, Confirmados, Decesos, Recuperados)
#Figura 2 confirmados ggplot
ggplot(data = datos1) +
geom_line(mapping = aes(x=Fecha, y=Confirmados))
#Figura 3 confirmados ggplot
ggplot(data = datos1) +
geom_line(mapping = aes(x=Fecha, y=Decesos))
#Figura 4 confirmados ggplot
ggplot(data = datos1)+
geom_line(mapping = aes(x=Fecha, y=Recuperados))
*Graficas animadas
#Animacion 1 simple
ggplot(data = datos1) +
ggtitle("Casos confirmados COVID-19 en Chile (Fuente: JHU CSSE)
@AlecSantanamoon") +
geom_line(mapping = aes(x=Fecha, y=Confirmados)) +
transition_reveal(Fecha)
#Animacion 2 simple
ggplot(data = datos1) +
ggtitle("Casos De Decesos COVID-19 en Chile (Fuente: JHU CSSE)
@AlecSantanamoon") +
geom_line(mapping = aes(x=Fecha, y=Decesos)) +
transition_reveal(Fecha)
#Animacion 3 simple
ggplot(data = datos1) +
ggtitle("Casos Recuperados COVID-19 en Chile (Fuente: JHU CSSE)
@AlecSantanamoon") +
geom_line(mapping = aes(x=Fecha, y=Recuperados)) +
transition_reveal(Fecha)
#Figura 5 multi ejes ggplot
ggplot(data = datos1) +
geom_line(aes(x=Fecha, y=Confirmados), color = 'red') +
geom_line(aes(x=Fecha, y=Decesos), color = 'blue') +
geom_line(aes(x=Fecha, y=Recuperados), color = 'green') +
theme_bw()
#Animacion 2
ggplot(data = datos1) +
geom_line(aes(x=Fecha, y=Confirmados), color = 'red') +
geom_line(aes(x=Fecha, y=Decesos), color = 'blue') +
geom_line(aes(x=Fecha, y=Recuperados), color = 'green') +
transition_reveal(Fecha)
#Grafica ineractiva compuesta
gcov <- ggplot(data = datos1) +
geom_line(aes(x=Fecha, y=Confirmados), color = 'red') +
geom_line(aes(x=Fecha, y=Decesos), color = 'blue') +
geom_line(aes(x=Fecha, y=Recuperados), color = 'green') +
ylab('COVID-19 México') + xlab('Fecha') +
transition_reveal(Fecha)
ggplotly(gcov)