Skip to content

Instantly share code, notes, and snippets.

@RamiKrispin
Created February 29, 2020 16:48
Show Gist options
  • Save RamiKrispin/9e1e29ce946cd2571dc7b8c38c9e60a4 to your computer and use it in GitHub Desktop.
Save RamiKrispin/9e1e29ce946cd2571dc7b8c38c9e60a4 to your computer and use it in GitHub Desktop.
Creating dist plot for China province
province_vec <- coronavirus %>%
dplyr::filter(type == "confirmed", Country.Region == "Mainland China") %>%
dplyr::group_by(Province.State) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
dplyr::arrange(-total) %>%
dplyr::select(province = Province.State)
coronavirus %>%
dplyr::filter(type == "confirmed", Country.Region == "Mainland China") %>%
dplyr::group_by(date, Province.State) %>%
dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
dplyr::ungroup() %>%
dplyr::mutate(province = Province.State) %>%
dplyr::mutate(province = factor(province, levels = province_vec$province)) %>%
plotly::plot_ly(
type = "scatter",
x = ~ date, y = ~ total,
color = ~ province,
mode = "lines",
fill = "tonexty",
groupnorm = 'percent',
stackgroup = 'one') %>%
plotly::layout(title = "",
xaxis = list(title = "",
showgrid = FALSE),
yaxis = list(title = "",
showgrid = FALSE,
ticksuffix = '%',
hoverformat = '.2f'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment