#script para analizar comportamiento de coronavirus
library(readr)
## Warning: package 'readr' was built under R version 3.6.3
library(tidyverse)
## -- Attaching packages ---------------------------------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.2.1 v dplyr 0.8.4
## v tibble 2.1.3 v stringr 1.4.0
## v tidyr 1.0.2 v forcats 0.4.0
## v purrr 0.3.3
## -- Conflicts ------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## 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(gganimate)
## Warning: package 'gganimate' was built under R version 3.6.3
library(gifski)
## Warning: package 'gifski' was built under R version 3.6.3
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"
#variables en marcos de datos
datos_conf <- read.csv(url_conf)
datos_decesos <- read.csv(url_decesos)
datos_recuperados <- read.csv(url_recuperados)
conf_Brazil <- t(datos_conf[datos_conf$Country.Region=="Brazil",])
dec_Brazil <- t(datos_decesos[datos_decesos$Country.Region=="Brazil",])
rec_Brazil <- t(datos_recuperados[datos_recuperados$Country.Region=="Brazil",])
#grafica simple
plot(conf_Brazil)
## Warning in xy.coords(x, y, xlabel, ylabel, log): NAs introducidos por coerción

#vector de Fecha
Fecha = seq(from=as.Date("2020-01-22"),to=as.Date("2020-04-22"),by="day")
vec1 <- as.vector(conf_Brazil)
vec2 <- vec1[5:96]
num1 <- as.numeric(vec2)
Confirmado <- as.vector(num1)
vec1 <- as.vector(dec_Brazil)
vec2 <- vec1[5:96]
num1 <- as.numeric(vec2)
Decesos<- as.vector(num1)
vec1 <- as.vector(rec_Brazil)
vec2 <- vec1[5:96]
num1 <- as.numeric(vec2)
Recuperados<- as.vector(num1)
datos1 <- data.frame(Fecha, Confirmado,Decesos,Recuperados)
ggplot(data=datos1)+
geom_line(mapping = aes(x=Fecha,y=Confirmado))

ggplot(data=datos1)+
geom_line(mapping = aes(x=Fecha,y=Decesos))

ggplot(data=datos1)+
geom_line(mapping = aes(x=Fecha,y=Recuperados))

ggplot(data=datos1)+
ggtitle("Casos confirmados COVID-19 en Brazil (Fuente:JHU CSSE)")+
geom_line(mapping = aes(x=Fecha,y=Confirmado))+
transition_reveal(Fecha)
#grafica multieje
ggplot(data=datos1)+
geom_line(aes(x=Fecha,y=Confirmado),color='blue')+
geom_line(aes(x=Fecha,y=Decesos),color='red')+
geom_line(aes(x=Fecha,y=Recuperados),color='green')+
ylab('Covid-19 Brazil') + xlab('Fecha') +
transition_reveal(Fecha)

gcov <- ggplot(data=datos1)+
geom_line(aes(x=Fecha,y=Confirmado),color='blue')+
geom_line(aes(x=Fecha,y=Decesos),color='red')+
geom_line(aes(x=Fecha,y=Recuperados),color='green')+
ylab('Covid-19 Brazil')+ xlab('Fecha') +
transition_reveal(Fecha)
ggplotly(gcov)