|
#---------------------------------------- |
|
# Plotting the daily new confirmed cases |
|
# China vs. rest of the world |
|
#---------------------------------------- |
|
# Data: coronavirus dataset from the coronavirus package |
|
# Using github version as it update the data on daily bases |
|
#---------------------------------------- |
|
# Installing most recent version from Github |
|
# must reset the R session after installation |
|
# install.packages("devtools") |
|
devtools::install_github("RamiKrispin/coronavirus") |
|
#---------------------------------------- |
|
# Loading the package and dataset |
|
library(coronavirus) |
|
data("coronavirus") |
|
#---------------------------------------- |
|
# Required packages |
|
# Data manipulation - dplyr and tidyr |
|
# Data viz - plotly |
|
#---------------------------------------- |
|
# Manipulate the data to daily confirmed cases China vs. rest of the world |
|
|
|
daily_confirmed <- coronavirus %>% |
|
dplyr::mutate(country = dplyr::if_else(Country.Region == "Mainland China", |
|
"China", |
|
"Rest of the World")) %>% |
|
dplyr::group_by(date, country) %>% |
|
dplyr::summarise(total = sum(cases)) %>% |
|
dplyr::ungroup() %>% |
|
tidyr::pivot_wider(names_from = country, values_from = total) |
|
|
|
#---------------------------------------- |
|
# Plotting the data |
|
|
|
daily_confirmed %>% |
|
plotly::plot_ly(x = ~date, |
|
y = ~ China, |
|
name = 'China', |
|
type = 'scatter', |
|
mode = 'none', |
|
stackgroup = 'one', |
|
groupnorm = 'percent', |
|
fillcolor = 'red') %>% |
|
plotly::add_trace(y = ~ `Rest of the World`, name = 'Rest of the World', fillcolor = 'yellow') %>% |
|
plotly::layout(title = "Coronavirus Daily Confirmed Cases Dist - China vs. Rest of the World", |
|
yaxis = list(title = "Proportion of New Cases", ticksuffix = '%'), |
|
xaxis = list(title = "Date"), |
|
legend = list(orientation = 'h'), |
|
paper_bgcolor = "black", |
|
plot_bgcolor = "black", |
|
font = list(color = 'white'), |
|
margin = list( |
|
l = 60, |
|
r = 40, |
|
b = 50, |
|
t = 50, |
|
pad = 4 |
|
)) |
|
|
|
|
|
|