idb1: (DEPRECATED) Retrieve data from the single-year-of-age IDB...

View source: R/idb-deprecated.R

idb1R Documentation

(DEPRECATED) Retrieve data from the single-year-of-age IDB dataset.

Description

(DEPRECATED) Retrieve data from the single-year-of-age IDB dataset.

Usage

idb1(
  country,
  year,
  variables = c("AGE", "AREA_KM2", "NAME", "POP"),
  start_age = NULL,
  end_age = NULL,
  sex = NULL,
  api_key = NULL
)

Arguments

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 idb_api_key(api_key).

Value

A data frame with the requested data.

See Also

https://api.census.gov/data/timeseries/idb/1year.html

Examples

## 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)

idbr documentation built on May 29, 2024, 8:39 a.m.

Related to idb1 in idbr...