pyramid: Population Pyramid Using ggplot2

Description Usage Arguments Value Examples

Description

Draws a population pyramid using ggplot2.

Usage

1
2
pyramid(data = NULL, m = NULL, gender_lab = NULL, age_col = "Age",
  gender_col = "Gender", pop_col = "Population")

Arguments

data

data frame containing columns on age, gender and population size.

m

Upper limit on the horizontal axis

gender_lab

Vector of length two containing a character string of gender group labels in data. Female label first, male second. If left as NULL, the function will guess labels from the unique values in the gender_col.

age_col

Character string for the name of the age column in data.

gender_col

Character string for the name of the gender labels column in data.

pop_col

Character string for the name of the projected population counts column in data.

Value

A ggplot bar charts forming a classic population pyramid.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
library(dplyr)
library(tidyr)

# data into tidy format for plotting
df0 <- sweden1993 %>%
  select(age, Nx_m, Nx_f) %>%
  gather(key = gender, value = pop, -age) %>%
  mutate(gender = gsub("Nx_", "", gender))
df0

# plot
pyramid(data = df0,
        gender_lab = c("f","m"),
        age_col = "age", gender_col = "gender", pop_col = "pop")

gjabel/demoproj documentation built on May 17, 2019, 6:01 a.m.