Learn R Programming

censuspyrID (version 1.0.2)

ageprof: Build Age-Profile Plot by Sex

Description

Create a line plot of population age profiles (5-year age groups) for a given province and year, with optional logarithmic scale. The plot is faceted by sex.

Usage

ageprof(data, log_scale = FALSE, color = "Fresh and bright")

Value

A ggplot2 object representing the age-profile plot, faceted by sex.

Arguments

data

A data frame of population data for a specific province and year, containing at least the variables: pop (population count), sex (coded as 1 = male, 2 = female), age5 (5-year age groups).

log_scale

Logical; whether to use a logarithmic scale for the Y-axis. Default is FALSE.

color

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

Details

The function produces an age-profile line chart where:

  • X-axis: Age (5-year groups).

  • Y-axis: Population counts (in thousands by default).

  • Separate lines are drawn for males and females.

  • Users can choose logarithmic scaling of the Y-axis.

See Also

pyr_single(), load_pop_data(), pop_data_by_reg(), pop_data_by_year(), get_code_label()

Examples

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

# Example with log scale
ageprof(data_idn, log_scale = TRUE)
}

Run the code above in your browser using DataLab