Skip to content

Instantly share code, notes, and snippets.

@YiLi225
Created March 29, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YiLi225/3ae9739142e14769f4f5845b915d2d2f to your computer and use it in GitHub Desktop.
Save YiLi225/3ae9739142e14769f4f5845b915d2d2f to your computer and use it in GitHub Desktop.
Create plotting dataset for plotly
#### Select the countries for plotting, and convert wide format to long
current_dat = country_data %>%
filter(Country.Region %in% selected_countries) %>%
reshape2::melt(.) %>%
set_colnames(c('Country', 'Status', 'Date', 'Total'))
## starts with the date when 1st case confirmed
find_case1_onwards <- function(country_name) {
case1_idx = which(current_dat[current_dat$Country == country_name, 'Total'] > 0)[1]
this_country = current_dat %>%
filter(Country == country_name) %>%
.[case1_idx:nrow(.), ]
}
current_dat_list = lapply(unique(current_dat$Country), find_case1_onwards)
current_dat = do.call(rbind, current_dat_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment