plot_popn
creates a visual representation of the population profile using survey data.
It can illustrate the distribution of age groups across genders or other categories,
and optionally includes average age or other statistics.
Usage
plot_popn(
data,
xVar,
yVar,
group = NULL,
weight = NULL,
meanVar = NULL,
colours = NULL,
title = "Population Structure",
subtitle = NULL,
xLab = "Population",
yLab = "Age",
addLabels = FALSE,
thresholdLab = 3,
nudgeLab = 0.2,
sizeLab = 11,
faceLab = c("plain", "bold", "italic", "bold.italic")
)
Arguments
- data
A data frame containing survey data.
- xVar
The gender variable (or a similar categorical variable) for the x-axis.
- yVar
The age group variable for the y-axis.
- group
An optional variable for additional grouping or comparison.
- weight
An optional weighting variable for the analysis.
- meanVar
An optional numeric variable to include average values in the plot.
- colours
A vector of three colors for male, female, and total. This parameter is optional.
- title
The title of the plot; defaults to "Population Structure".
- subtitle
The subtitle for the plot, particularly useful in grouped plots; defaults to the question associated with the group variable.
- xLab
The title for the x-axis; defaults to "Population (%)".
- yLab
The title for the y-axis; defaults to "Age".
- addLabels
A logical indicating whether to add percentage labels to the plot; defaults to
FALSE
.- thresholdLab
A numeric threshold for label placement inside or outside the bars.
- nudgeLab
A numeric value to adjust the horizontal position of labels.
- sizeLab
The font size for labels.
- faceLab
The font style for labels; can be "plain", "bold", "italic", or "bold.italic".