Learn R Programming

censuspyrID (version 1.0.2)

pyr_single: Build a Single Population Pyramid

Description

Create a population pyramid for a given dataset (specific province and year), either in absolute counts or in proportions, with customizable color palettes.

Usage

pyr_single(data, use_prop = FALSE, color = "Fresh and bright")

Value

A ggplot object representing the population pyramid.

Arguments

data

A data frame containing population data for a specific province and year. Must include variables sex, age5, and pop.

use_prop

Logical, default FALSE. If TRUE, the pyramid will be shown in proportions instead of absolute counts.

color

Character string indicating the color palette name to use for the pyramid. Available palettes come from ggthemes::canva_palettes, e.g., "Fresh and bright".

See Also

ageprof(), pyr_trends(), load_pop_data(), pop_data_by_reg(), pop_data_by_year(), get_code_label()

Examples

Run this code
if (FALSE) {
# Example data for Indonesia, 2020
data_idn <- pop_data_by_year(load_pop_data(), 2020) |>
  pop_data_by_reg(0) #Indonesia

# Absolute count pyramid
pyr_single(data_idn)

# Proportional pyramid with different palette
pyr_single(data_idn, use_prop = TRUE, color = "Professional and modern")
}

Run the code above in your browser using DataLab