get_wpp | R Documentation |
Downloads data on demographic indicators in UN DESA WPP. Requires a working internet connection.
get_wpp( indicator = NULL, indicator_file = NULL, pop_age = c("total", "single", "five"), pop_sex = c("total", "both", "male", "female", "all"), pop_freq = c("annual", "five"), pop_date = c("jul1", "jan1", "jan1-dec31"), variant_id = 2, wpp_version = 2022, clean_names = FALSE, fct_age = TRUE, drop_id_cols = FALSE, tidy_pop_sex = FALSE, add_regions = FALSE, add_iso_codes = FALSE, messages = TRUE, server = c("github", "local") )
indicator |
Character string based on the |
indicator_file |
Character string based on the |
pop_age |
Character string for population age groups if |
pop_sex |
Character string for population sexes if |
pop_freq |
Character string for frequency of population data if |
pop_date |
Character string for frequency of population data if |
variant_id |
Numeric value(s) based on the |
wpp_version |
Integer for WPP version. Default of |
clean_names |
Logical to indicate if column names should be cleaned |
fct_age |
Logical to indicate if |
drop_id_cols |
Logical to indicate if |
tidy_pop_sex |
Logical to indicate if columns for sex specific population data should be stacked into single population column with an accompanying new sex column. |
add_regions |
Logical to indicate if to add a |
add_iso_codes |
Logical to indicate if to add a |
messages |
Logical to not suppress printing of messages. |
server |
Character string for location to download data from. Default of |
Indicators must use the name corresponding to the name
column in in the wpp_indicators data frame.
The find_indicator() function can be used to look up the indicator code and availability by variants
There are 114 different indicators in WPP data (starting from 1998). See the full table of the different indicators available in each WPP.
The variant_id
argument must be one or more numbers from the var_id
column in the wpp_indicators data frame.
Not all indicators area available in all variants. Use the find_indicator() function to check availability.
There are 14 different variants in WPP data (starting from 1998).
var_id | variant |
2 | Medium |
3 | High |
4 | Low |
5 | Constant fertility |
6 | Instant replacement |
7 | Zero migration |
8 | Constant mortality |
9 | No change |
10 | Momentum |
16 | Instant replacement zero migration |
202 | Median PI (BHM median in WPP2015) |
203 | Upper 80 PI |
204 | Lower 80 PI |
206 | Upper 95 PI |
207 | Lower 95 PI |
A tibble with downloaded data in tidy format
# single indicator from medium variant of latest WPP get_wpp(indicator = "TFR") # single indicator from multiple variants of latest WPP get_wpp(indicator = "TFR", variant_id = c(2, 3, 4)) # some indicators appear in multiple file groups, for example Births # represents total number of births in the country in the # Demographic_Indicators file (chosen by default) get_wpp(indicator = "Births") # specify indicator_file to get number of births by mothers 5-year age group get_wpp(indicator = c("Births", "ASFR"), indicator_file = "Fertility_by_Age5", drop_id_cols = TRUE) # PopTotal, PopMale and PopFemale indicators are in many WPP files with # a wide range granularity. Set indicator = "pop" and use the pop_sex, # pop_age, pop_freq and pop_date to get desired data from the appropriate # indicator_file... # when using indicator = "pop" get_wpp() defaults to annual total population # (summed over age and sex) get_wpp(indicator = "pop") # use pop_sex to get specific sexes (or both or all) get_wpp(indicator = "pop", pop_sex = "male") # use pop_age to specify age groups get_wpp(indicator = "pop", pop_sex = "both", pop_age = "five") # use pop_date to specify populations at start of year (rather than mid-year) get_wpp(indicator = "pop", pop_sex = "female", pop_age = "five", pop_date = "jan1") # tidy sex into a single column and drop id columns get_wpp(indicator = "pop", pop_sex = "both", pop_age = "five", tidy_pop_sex = TRUE, drop_id_cols = TRUE) # alternatively use indicator_file to select the desired version of population indicator(s) get_wpp(indicator = c("PopTotal", "PopMale", "PopFemale"), indicator_file = "TotalPopulationBySex") # clean column names get_wpp(indicator = c("SRB", "NetMigrations", "PopGrowthRate"), clean_names = TRUE, drop_id_cols = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.