Learn R Programming

censuspyrID (version 1.0.2)

pyr_trends: Build Population Pyramid Trends

Description

Create trend plots of population pyramids over multiple census years for a given region. Users can choose between a grid layout of pyramids or an overlay of age profiles across years.

Usage

pyr_trends(data, mode = 1, use_prop = FALSE, color = "Fresh and bright")

Value

A ggplot2 object representing the population pyramid trend plot.

Arguments

data

A data frame of population data for a specific region across census years, containing at least: year, age5, sex, and pop.

mode

Integer; visualization mode: 1 for grid pyramids, 2 for overlayed age profiles. Default is 1.

use_prop

Logical; whether to show proportions instead of absolute counts. Default is FALSE.

color

Character; the name of a Canva color palette available in ggthemes::canva_palettes. Default is "Fresh and bright".

Details

Two visualization modes are available:

  • mode = 1: Grid of population pyramids (faceted by year).

  • mode = 2: Overlayed age profiles with separate lines by year.

Population counts can be displayed either as absolute numbers (default, in thousands) or as proportions (use_prop = TRUE).

See Also

area_trends(), load_pop_data(), pop_data_by_reg(), get_code_label()

Examples

Run this code
if (FALSE) {
# Example: pyramid trends for Indonesia
data_idn <- load_pop_data(harmonized = TRUE, smoothing = 1) |>
  pop_data_by_reg(0) #Indonesia
pyr_trends(data_idn, mode = 1)  # grid layout

# Overlay mode with proportions
pyr_trends(data_idn, mode = 2, use_prop = TRUE)
}

Run the code above in your browser using DataLab