View source: R/idb-deprecated.R
| idb1 | R Documentation | 
(DEPRECATED) Retrieve data from the single-year-of-age IDB dataset.
idb1(
  country,
  year,
  variables = c("AGE", "AREA_KM2", "NAME", "POP"),
  start_age = NULL,
  end_age = NULL,
  sex = NULL,
  api_key = NULL
)
| country | The two-character country FIPS code, or a valid country name. | 
| year | The year for which you'd like to retrieve data | 
| variables | A vector of variables. If left blank, will return age, area in square kilometers, the name of the country, and the population size of the age group. | 
| start_age | (optional) The first age for which you'd like to retrieve data. | 
| end_age | (optional) The second age group for which you'd like to retrieve data. | 
| sex | (optional) One of 'both', 'male', or 'female'. | 
| api_key | The user's Census API key.  Can be supplied here or set globally in an idbr session with
 | 
A data frame with the requested data.
https://api.census.gov/data/timeseries/idb/1year.html
## Not run: 
# Projected population pyramid of China in 2050 with idbr and plotly
library(idbr)
library(plotly)
library(dplyr)
idb_api_key('Your API key goes here')
male <- idb1('CH', 2050, sex = 'male') %>%
  mutate(POP = POP * -1,
         SEX = 'Male')
female <- idb1('CH', 2050, sex = 'female') %>%
   mutate(SEX = 'Female')
china <- rbind(male, female) %>%
   mutate(abs_pop = abs(POP))
plot_ly(china, x = POP, y = AGE, color = SEX, type = 'bar', orientation = 'h',
        hoverinfo = 'y+text+name', text = abs_pop, colors = c('red', 'gold')) %>%
  layout(bargap = 0.1, barmode = 'overlay',
         xaxis = list(tickmode = 'array', tickvals = c(-10000000, -5000000, 0, 5000000, 10000000),
                     ticktext = c('10M', '5M', '0', '5M', '10M')),
         title = 'Projected population structure of China, 2050')
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.