From 82263c121d046364fb84c1940d55f4ad17943373 Mon Sep 17 00:00:00 2001 From: Francesca Vitalini Date: Mon, 30 Mar 2020 15:29:23 +0200 Subject: [PATCH] release preps 1.1.3 (#54) * release preps 1.1.3 - Integrate population data for map (#29) --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 4 + R/get_data.R | 59 +++++++++ R/mod_map.R | 30 +++-- inst/population_data/pop.csv | 243 +++++++++++++++++++++++++++++++++++ man/get_pop_data.Rd | 27 ++++ 7 files changed, 357 insertions(+), 9 deletions(-) create mode 100644 inst/population_data/pop.csv create mode 100644 man/get_pop_data.Rd diff --git a/DESCRIPTION b/DESCRIPTION index eae44a5e..b1f37107 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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'), diff --git a/NAMESPACE b/NAMESPACE index 5f82fec9..c5afb364 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/NEWS.md b/NEWS.md index cfbf0867..d671be31 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/get_data.R b/R/get_data.R index 13f678c6..5d9a6a77 100644 --- a/R/get_data.R +++ b/R/get_data.R @@ -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 +} diff --git a/R/mod_map.R b/R/mod_map.R index f89a736a..0bb5ea79 100644 --- a/R/mod_map.R +++ b/R/mod_map.R @@ -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.") ) @@ -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 ---- @@ -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, @@ -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)) ) }) diff --git a/inst/population_data/pop.csv b/inst/population_data/pop.csv new file mode 100644 index 00000000..e1996086 --- /dev/null +++ b/inst/population_data/pop.csv @@ -0,0 +1,243 @@ +"";"Country.Region";"population" +"1";"China";"1401667160" +"2";"India";"1359530533" +"3";"United States";"329413981" +"4";"Indonesia";"266911900" +"5";"Pakistan";"218873520" +"6";"Brazil";"211226388" +"7";"Nigeria";"200963599" +"8";"Bangladesh";"168231270" +"9";"Russia";"146780720" +"10";"Mexico";"126577691" +"11";"Japan";"126010000" +"12";"Philippines";"108376492" +"13";"Egypt";"100103288" +"14";"Ethiopia";"98665000" +"15";"Vietnam";"96208984" +"16";"DR Congo";"86790567" +"17";"Iran";"83262859" +"18";"Turkey";"83154997" +"19";"Germany";"83149300" +"20";"France";"67064000" +"21";"Thailand";"66478917" +"22";"United Kingdom";"66435600" +"23";"Italy";"60247214" +"24";"South Africa";"58775022" +"25";"Tanzania";"55890747" +"26";"Myanmar";"54339766" +"27";"South Korea";"51780579" +"28";"Colombia";"49395678" +"29";"Kenya";"47564296" +"30";"Spain";"47100396" +"31";"Argentina";"44938712" +"32";"Algeria";"43000000" +"33";"Sudan";"42327265" +"34";"Ukraine";"41902416" +"35";"Uganda";"40299300" +"36";"Iraq";"39127900" +"37";"Poland";"38386000" +"38";"Canada";"37949851" +"39";"Morocco";"35832595" +"40";"Saudi Arabia";"34218169" +"41";"Uzbekistan";"34057261" +"42";"Malaysia";"32712760" +"43";"Afghanistan";"32225560" +"44";"Venezuela";"32219521" +"45";"Peru";"32131400" +"46";"Angola";"31127674" +"47";"Ghana";"30280811" +"48";"Nepal";"29609623" +"49";"Yemen";"29161922" +"50";"Mozambique";"28571310" +"51";"Cameroon";"25876000" +"52";"Ivory Coast";"25823071" +"53";"Madagascar";"25680342" +"54";"Australia";"25639623" +"55";"North Korea";"25450000" +"56";"Taiwan";"23604265" +"57";"Niger";"22314743" +"58";"Sri Lanka";"21803000" +"59";"Burkina Faso";"20870060" +"60";"Mali";"19973000" +"61";"Romania";"19405156" +"62";"Chile";"19107216" +"63";"Kazakhstan";"18659072" +"64";"Malawi";"17563749" +"65";"Netherlands";"17442281" +"66";"Ecuador";"17439824" +"67";"Zambia";"17381168" +"68";"Syria";"17070135" +"69";"Guatemala";"16604026" +"70";"Senegal";"16209125" +"71";"Chad";"15692969" +"72";"Somalia";"15442905" +"73";"Cambodia";"15288489" +"74";"Zimbabwe";"15159624" +"75";"South Sudan";"12778250" +"76";"Rwanda";"12374397" +"77";"Guinea";"12218357" +"78";"Benin";"11733059" +"79";"Tunisia";"11722038" +"80";"Haiti";"11577779" +"81";"Belgium";"11524454" +"82";"Bolivia";"11469896" +"83";"Cuba";"11209628" +"84";"Burundi";"10953317" +"85";"Greece";"10724599" +"86";"Czechia";"10681161" +"87";"Jordan";"10631296" +"88";"Dominican Rep.";"10358320" +"89";"Sweden";"10333456" +"90";"Portugal";"10276617" +"91";"Azerbaijan";"10067108" +"92";"Hungary";"9772756" +"93";"United Arab Emirates";"9770529" +"94";"Belarus";"9413446" +"95";"Israel";"9168750" +"96";"Honduras";"9158345" +"97";"Tajikistan";"9127000" +"98";"Papua New Guinea";"8935000" +"99";"Austria";"8902600" +"100";"Switzerland";"8586550" +"101";"Sierra Leone";"7901454" +"102";"Togo";"7538000" +"103";"Hong Kong";"7500700" +"104";"Paraguay";"7152703" +"105";"Laos";"7123205" +"106";"Bulgaria";"7000039" +"107";"Serbia";"6963764" +"108";"Lebanon";"6855713" +"109";"Libya";"6777452" +"110";"El Salvador";"6704864" +"111";"Kyrgyzstan";"6490300" +"112";"Nicaragua";"6460411" +"113";"Turkmenistan";"5942089" +"114";"Denmark";"5822763" +"115";"Singapore";"5703600" +"116";"Finland";"5527573" +"117";"Central African Republic";"5496011" +"118";"Slovakia";"5456362" +"119";"Congo";"5380508" +"120";"Norway";"5367580" +"121";"Costa Rica";"5058007" +"122";"Palestine";"4976684" +"123";"New Zealand";"4968679" +"124";"Ireland";"4921500" +"125";"Oman";"4664790" +"126";"Liberia";"4475353" +"127";"Kuwait";"4420110" +"128";"Panama";"4218808" +"129";"Mauritania";"4077347" +"130";"Croatia";"4076246" +"131";"Georgia";"3723464" +"132";"Uruguay";"3518552" +"133";"Eritrea";"3497117" +"134";"Mongolia";"3306493" +"135";"Bosnia and Herz.";"3301000" +"136";"Puerto Rico(US)";"3193694" +"137";"Armenia";"2957500" +"138";"Albania";"2862427" +"139";"Lithuania";"2793350" +"140";"Qatar";"2747282" +"141";"Jamaica";"2726667" +"142";"Moldova";"2681735" +"143";"Namibia";"2458936" +"144";"Gambia";"2347706" +"145";"Botswana";"2338851" +"146";"Gabon";"2172579" +"147";"Slovenia";"2094060" +"148";"Macedonia";"2077132" +"149";"Lesotho";"2007201" +"150";"Latvia";"1906800" +"151";"Kosovo";"1795666" +"152";"Guinea-Bissau";"1604528" +"153";"Bahrain";"1543300" +"154";"East Timor";"1387149" +"155";"Trinidad and Tobago";"1363985" +"156";"Equatorial Guinea";"1358276" +"157";"Estonia";"1328360" +"158";"Mauritius";"1265985" +"159";"Eswatini";"1093238" +"160";"Djibouti";"1078373" +"161";"Fiji";"884887" +"162";"Cyprus";"8759" +"163";"Comoros";"873724" +"164";"Guyana";"782766" +"165";"Bhutan";"741672" +"166";"Solomon Islands";"680806" +"167";"Macao";"6796" +"168";"Montenegro";"622359" +"169";"Luxembourg";"613894" +"170";"Western Sahara";"582463" +"171";"Suriname";"581372" +"172";"Cape Verde";"550483" +"173";"Malta";"493559" +"174";"Transnistria";"469" +"175";"Brunei";"4424" +"176";"Belize";"408487" +"177";"Bahamas";"38534" +"178";"Maldives";"374775" +"179";"Iceland";"36426" +"180";"Northern Cyprus";"351965" +"181";"Vanuatu";"3045" +"182";"Barbados";"287025" +"183";"New Caledonia(France)";"2822" +"184";"French Polynesia(France)";"275918" +"185";"Abkhazia";"244832" +"186";"São Tomé and Príncipe";"201784" +"187";"Samoa";"200874" +"188";"Saint Lucia";"178696" +"189";"Guam(US)";"1724" +"190";"Curaçao(Netherlands)";"158665" +"191";"Artsakh";"148" +"192";"Kiribati";"1201" +"193";"Aruba(Netherlands)";"112309" +"194";"Grenada";"112003" +"195";"Saint Vincent and the Grenadines";"110608" +"196";"Jersey(UK)";"1068" +"197";"U.S. Virgin Islands(US)";"104578" +"198";"F.S. Micronesia";"104468" +"199";"Tonga";"100651" +"200";"Seychelles";"97625" +"201";"Antigua and Barbuda";"96453" +"202";"Isle of Man(UK)";"83314" +"203";"Andorra";"77543" +"204";"Dominica";"71808" +"205";"Cayman Islands(UK)";"65813" +"206";"Bermuda(UK)";"64027" +"207";"Guernsey(UK)";"62792" +"208";"American Samoa(US)";"567" +"209";"Greenland(Denmark)";"56081" +"210";"Northern Mariana Islands(US)";"562" +"211";"Marshall Islands";"555" +"212";"South Ossetia";"53532" +"213";"Saint Kitts and Nevis";"52823" +"214";"Faeroe Is.";"52124" +"215";"Turks and Caicos Islands(UK)";"41369" +"216";"Sint Maarten(Netherlands)";"40614" +"217";"Liechtenstein";"38557" +"218";"Monaco";"383" +"219";"Saint Martin(France)";"35746" +"220";"Gibraltar(UK)";"33701" +"221";"San Marino";"33574" +"222";"British Virgin Islands(UK)";"3003" +"223";"Åland Islands(Finland)";"29789" +"224";"Palau";"179" +"225";"Cook Islands(NZ)";"152" +"226";"Anguilla(UK)";"14869" +"227";"Wallis and Futuna(France)";"117" +"228";"Nauru";"11" +"229";"Tuvalu";"102" +"230";"St-Barthélemy";"9793" +"231";"Saint Pierre and Miquelon(France)";"6008" +"232";"Saint Helena, Ascension";"5633" +"233";"and Tristan da Cunha(UK)";"" +"234";"Montserrat(UK)";"4989" +"235";"Falkland Islands(UK)";"3198" +"236";"Christmas Island(Australia)";"1928" +"237";"Norfolk Island(Australia)";"1756" +"238";"Niue(NZ)";"152" +"239";"Tokelau(NZ)";"14" +"240";"Vatican";"799" +"241";"Cocos (Keeling) Islands(Australia)";"538" +"242";"Pitcairn Islands(UK)";"50" diff --git a/man/get_pop_data.Rd b/man/get_pop_data.Rd new file mode 100644 index 00000000..6eb3192b --- /dev/null +++ b/man/get_pop_data.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_data.R +\name{get_pop_data} +\alias{get_pop_data} +\title{population data} +\usage{ +get_pop_data(data) +} +\arguments{ +\item{data}{data.frame} +} +\value{ +global tibble of confirmed, deaths, active and recovered for each day by population +} +\description{ +population data +} +\examples{ +\dontrun{ +orig_data <- get_timeseries_full_data() \%>\% + get_timeseries_by_contagion_day_data() \%>\% + select(-ends_with("rate")) +data <- orig_data \%>\% align_country_names() + +} + +}