Learn R Programming

Bernadette (version 1.1.6)

plot_age_distribution: Bar plot of the age distribution

Description

Bar plot of the age distribution

Usage

plot_age_distribution(x)

Value

A ggplot object that can be further customized using the

ggplot2 package.

Arguments

x

data.frame; the age distribution matrix. See age_distribution and aggregate_age_distribution.

References

United Nations, Department of Economic and Social Affairs, Population Division (2019). World Population Prospects 2019, Online Edition. Rev. 1.

Examples

Run this code
# Import the age distribution for Greece in 2020:
age_distr <- age_distribution(country = "Greece", year = 2020)

plot_age_distribution(age_distr)

# Lookup table:
lookup_table <- data.frame(Initial = age_distr$AgeGrp,
                           Mapping = c(rep("0-39",  8),
                                       rep("40-64", 5),
                                       rep("65+"  , 3)))

# Aggregate the age distribution table:
aggr_age <- aggregate_age_distribution(age_distr, lookup_table)

# Plot the aggregated age distribution matrix:
plot_age_distribution(aggr_age)

Run the code above in your browser using DataLab