|
library(coronavirus) |
|
df <- coronavirus %>% |
|
# dplyr::filter(date == max(date)) %>% |
|
dplyr::group_by(Country.Region, type) %>% |
|
dplyr::summarise(total = sum(cases)) %>% |
|
tidyr::pivot_wider(names_from = type, |
|
values_from = total) %>% |
|
dplyr::arrange(-confirmed) %>% |
|
dplyr::ungroup() %>% |
|
dplyr::mutate(country = factor(Country.Region, levels = Country.Region)) |
|
|
|
df$flag <- NA |
|
df$flag[1:10] <- "Top 10 Countries" |
|
|
|
|
|
|
|
corona<- plotly::highlight_key(df) |
|
widgets <- crosstalk::bscols( |
|
widths = c(12, 12, 12), |
|
crosstalk::filter_select("country", "Country", corona, ~country) |
|
# crosstalk:: filter_checkbox("flag", "Top 10", corona, ~flag, inline = FALSE) |
|
# filter_slider("confirmed", "Confirmed Cases", corona, ~confirmed), |
|
# filter_slider("recovered", "Recovered Cases", corona, ~recovered) |
|
) |
|
crosstalk::bscols( |
|
widths = c(4, 12), widgets, |
|
plotly::plot_ly(data = corona, x = ~ country, y = ~ confirmed, type = "bar", name = "Confirmed") %>% |
|
plotly::add_trace(y = ~ recovered, name = "Recovered") %>% |
|
plotly::add_trace(y = ~ death, name = "Death") %>% |
|
plotly::layout(barmode = 'stack', |
|
yaxis = list(title = "Total Cases (log scaled)", |
|
type = "log"), |
|
xaxis = list(title = "Country")) |
|
|
|
) |