Pyramid Chart

pyramid_chart(
  data,
  xvar,
  yvar,
  levelvar,
  groupvar,
  xlab,
  alpha_set,
  chartcolors
)

Arguments

data

dataframe demography data

xvar

value x-axis

yvar

value y-axis

levelvar

Factor two factor levels, one for each pyramid

groupvar

Factor two factor levels, one for each side of a pyramid

xlab

text for x-axis label

alpha_set

Value specify transparency of symbols

chartcolors

vector two colors, one for each side of a pyramid

Value

ggplot object

Examples

demography |>
  dplyr::mutate(
    Type = as.factor(paste0("Type ", Type)),
    figprev = ifelse(
      Gender == "Females", -1 * Prevalence / 100000, Prevalence / 100000
    ),
    Sex = Gender
  ) |>
  pyramid_chart(
    levelvar = "Type", xvar = "figprev", yvar = "Age",
    groupvar = "Sex", alpha_set = 0.7, chartcolors = colfun()$fig2_colors,
    xlab = "Prevalence (x 100 000)"
  )