get_idb | R Documentation |
Get Data from the US Census Bureau's International Data Base API
get_idb(
country,
year,
variables = NULL,
concept = NULL,
age = NULL,
sex = NULL,
geometry = FALSE,
resolution = c("low", "high"),
api_key = NULL
)
country |
A country name or vector of country names. Can be specified as ISO-2 codes
as well. Use |
year |
A single year or vector of years for which you'd like to request data. |
variables |
A character string or vector of variables representing data you would like
to request. If you are specifying an age or sex subset, this should be kept as |
concept |
Variables in the IDB are organized by concepts; if specified, request all
variables for a given concept. Use |
age |
A vector of ages for which you would like to request population data. If specified, will return data from the 1-year-age-band IDB API. Should not be used when
|
sex |
One or more of "both", "male", or "female". If specified, will return data
from the 1-year-age-band IDB API. Should not be used when |
geometry |
If |
resolution |
one of |
api_key |
Your Census API key. Can be supplied as part of the function call or
set globally with the |
A tibble or sf tibble of data from the International Data Base API.
## Not run:
# Get data from the 1-year-age-band dataset by sex for China from
# 1990 through 2021
library(idbr)
china_data <- get_idb(
country = "China",
year = 1990:2021,
age = 1:100,
sex = c("male", "female")
)
# Get data on life expectancy at birth for all countries in 2021 and
# make a map with ggplot2
library(idbr)
library(tidyverse)
lex <- get_idb(
country = "all",
year = 2021,
variables = c("name", "e0"),
geometry = TRUE
)
ggplot(lex, aes(fill = e0)) +
theme_bw() +
geom_sf() +
coord_sf(crs = 'ESRI:54030') +
scale_fill_viridis_c() +
labs(fill = "Life expectancy at birth (2021)")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.