Skip to content

Commit

Permalink
release preps 1.1.3 (#54)
Browse files Browse the repository at this point in the history
* release preps 1.1.3

- Integrate population data for map (#29)
  • Loading branch information
fvitalini authored Mar 30, 2020
1 parent 849f144 commit 82263c1
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: Covid19
Title: Covid-19 Data Analysis
Version: 1.1.2
Version: 1.1.3
Authors@R:
c(person("Francesca", "Vitalini", role = c("cre", "aut"),
email = 'francesca.vitalini@mirai-solutions.com'),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export(getTableOptions)
export(get_Covid19_version)
export(get_daily_data)
export(get_date_data)
export(get_pop_data)
export(get_timeseries_by_contagion_day_data)
export(get_timeseries_country_data)
export(get_timeseries_data)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Covid19 1.1.3 (2020-03-30)

- Integrate population data for map (#29)

### Covid19 1.1.2 (2020-03-26)

- JHU data source currently deprecated: switch (temporarily) to https://github.com/bumbeishvili/covid19-daily-data (#48). Users are alerted on app launch.
Expand Down
59 changes: 59 additions & 0 deletions R/get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,62 @@ get_date_data <- function(data, date){
mutate(death_rate = 100*new_deaths / lag(deaths)) %>%
ungroup()
}


#' population data
#' @rdname get_pop_data
#'
#' @param data data.frame
#'
#' @import dplyr
#' @import tidyr
#'
#' @return global tibble of confirmed, deaths, active and recovered for each day by population
#'
#' @examples
#' \dontrun{
#' orig_data <- get_timeseries_full_data() %>%
#' get_timeseries_by_contagion_day_data() %>%
#' select(-ends_with("rate"))
#' data <- orig_data %>% align_country_names()
#'
#'}
#'
#' @export
get_pop_data <- function(data){
#Reference: https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population
# pop_url <- "https://raw.githubusercontent.com/DrFabach/Corona/master/pop.csv"
# pop_raw <- readLines(pop_url)
# pop <- data.frame(pop_raw[2:length(pop_raw)], stringsAsFactors = FALSE) %>%
# setNames(pop_raw[1])
# pop <- pop %>%
# separate(col = "Country;Population", into = c("Country.Region", "population"), sep = ";")
# write.csv2(pop, "./inst/population_data/pop.csv")
population <- read.csv2(system.file("population_data/pop.csv", package = "Covid19"),stringsAsFactors = F) %>%
select(-X)
population$Country.Region <- population$Country.Region %>%
recode(
"Ivory Coast" = "C\\u00f4te d'Ivoire",
"DR Congo" = "Republic of the Congo",
"United Arab Emirates" = "UAE",
"East Timor" = "Timor-Leste" ,
"Saint Vincent and the Grenadines" = "St. Vincent Grenadines",
"Puerto Rico(US)" = "Puerto Rico",
"Comoros" = "Mayotte",
"Guam(US)" = "Guam",
"Greenland(Denmark)" = "Greenland",
"Eswatini" = "eSwatini",
"Isle of Man(UK)" = "Channel Islands",
"Central African Republic" = "CAR",
"Cape Verde" = "Cabo Verde",
"Antigua and Barbuda" = "Antigua and Barb.",
"United States" = "United States of America"
)

data_pop <- data %>%
mutate(Country.Region = country_name) %>%
left_join(population) %>%
select(-Country.Region)

data_pop
}
30 changes: 22 additions & 8 deletions R/mod_map.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod_map_ui <- function(id){
top = 10, left = 10, draggable = F,
div(style = "margin:10px;",
radioButtons(inputId = ns("radio_choices"), label = "", choices = c("confirmed", "deaths", "recovered", "active"), selected = "confirmed", inline = T),
radioButtons(inputId = ns("radio_pop"), label = "", choices = c("total", "per 1M pop"), selected = "total", inline = T),
uiOutput(ns("slider_ui")),
helpText("The detail of each country can be obtained by clicking on it.")
)
Expand Down Expand Up @@ -47,14 +48,16 @@ mod_map_server <- function(input, output, session, data){
countries_data <- load_countries_data(destpath = system.file("./countries_data", package = "Covid19"))

data_clean <- reactive({
data <- data() %>% align_country_names()
data <- data() %>%
aggregate_province_timeseries_data() %>%
align_country_names()

data$country_name <- as.character(unique(as.character(countries_data$NAME))[charmatch(data$Country.Region, unique(as.character(countries_data$NAME)))])

data <- data %>%
data_clean <- data %>%
filter(!is.na(country_name))

data
data_clean
})

# UI controls ----
Expand All @@ -66,17 +69,28 @@ mod_map_server <- function(input, output, session, data){

# Data for a given date
data_date <- reactive({
data_clean() %>%
data_date <- data_clean() %>%
filter(date == req(input$slider_day)) %>%
select(-c(Country.Region, Province.State, Lat, Long, date, contagion_day)) %>%
select(-c(Country.Region, date, contagion_day)) %>%
group_by(country_name) %>%
summarise_each(sum)
summarise_each(sum) %>%
ungroup() %>%
get_pop_data()
data_date
})

data_plot <- reactive({
data_selected <- data_date() %>%
bind_cols(data_date()[,input$radio_choices] %>%
setNames("indicator")) %>%
setNames("indicator"))

if (req(input$radio_pop) == "per 1M pop") {
data_selected <- data_selected %>%
# percentage of indicator per 1M population
mutate(indicator = round(1000000 * .$indicator / .$population))
}

data_selected <- data_selected %>%
select(country_name, indicator)

data_plot <- sp::merge(countries_data,
Expand Down Expand Up @@ -151,7 +165,7 @@ mod_map_server <- function(input, output, session, data){
bins = log(10^(seq(0,log10(roundUp(max_value())),1))),
values = log(1:roundUp(max_value())),
data = log(1:roundUp(max_value())),
labFormat = labelFormat(transform = function(x) roundUp(exp(x)), suffix = " cases")
labFormat = labelFormat(transform = function(x) roundUp(exp(x)), suffix = paste0(" cases ", input$radio_pop))
)
})

Expand Down
Loading

0 comments on commit 82263c1

Please sign in to comment.