Description Usage Arguments Value Examples
Draws a population pyramid using ggplot2.
1 2 |
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 |
age_col |
Character string for the name of the age column in |
gender_col |
Character string for the name of the gender labels column in |
pop_col |
Character string for the name of the projected population counts column in |
A ggplot bar charts forming a classic population pyramid.
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.