Created
March 29, 2020 18:12
-
-
Save YiLi225/3ae9739142e14769f4f5845b915d2d2f to your computer and use it in GitHub Desktop.
Create plotting dataset for plotly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### 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