| Title: | Population Pyramids |
|---|---|
| Description: | Functions that facilitate the elaboration of population pyramids. |
| Authors: | Jorge L. C. Musaja [aut, cre] |
| Maintainer: | Jorge L. C. Musaja <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.1 |
| Built: | 2026-05-26 09:45:42 UTC |
| Source: | https://github.com/musajajorge/poppyramid |
Requires the following aesthetics:
x
y
split: The variable on which to stratify the plot
geom_label_pyramid( mapping = NULL, data = NULL, stat = "identity", position = "nudge", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )geom_label_pyramid( mapping = NULL, data = NULL, stat = "identity", position = "nudge", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer.
Cannot be jointy specified with
|
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Other aesthetics are passed onto 'geom_label'
A column plot with back-to-back labels, stratified on some input variables.
geom_pyramid( mapping = NULL, data = NULL, stat = "identity", position = "stack", ..., just = 0.5, width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )geom_pyramid( mapping = NULL, data = NULL, stat = "identity", position = "stack", ..., just = 0.5, width = NULL, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
just |
Adjustment for column placement. Set to |
width |
Bar width. By default, set to 90% of the |
na.rm |
If |
orientation |
The orientation of the layer. The default ( |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
Requires the following aesthetics:
x
y
split: The variable on which to stratify the plot
Other aesthetics are passed onto 'geom_col'
Label values by absolute value
labeller_abs(...)labeller_abs(...)
... |
Extra arguments passed to 'format' |
Function that can be used to format values, best used inside 'scale_*' or 'geom_label'-like functions.
Creates a dataframe in long format and in percent
percDF(df, age, sex, pop)percDF(df, age, sex, pop)
df |
Name of dataframe |
age |
Age or age group. Write the parameter in quotation marks. |
sex |
Sex or other categorical grouping variable. Write the parameter in quotation marks. |
pop |
Population (in numerical value). Write the parameter in quotation marks. |
The dataframe in long format and in percentage
df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) df <- percDF(df, "Age", "Sex", "Population")df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) df <- percDF(df, "Age", "Sex", "Population")
Create a population percentage pyramid graph
plotPercPyramid( df, age, sex, perpop, labx = perpop, laby = age, twocolors = c("#41ae76", "#ef6548"), rotation = 0, n.breaks = 20, value.labels = TRUE, position.value.labels = "in", size.value.labels = 3 )plotPercPyramid( df, age, sex, perpop, labx = perpop, laby = age, twocolors = c("#41ae76", "#ef6548"), rotation = 0, n.breaks = 20, value.labels = TRUE, position.value.labels = "in", size.value.labels = 3 )
df |
Name of dataframe |
age |
Age or age group. Write the parameter in quotation marks. |
sex |
Sex or other categorical grouping variable. Write the parameter in quotation marks. |
perpop |
Percentage of population (in numerical value). Write the parameter in quotation marks. |
labx |
X-axis label |
laby |
Y-axis label |
twocolors |
Two colors for the pyramid |
rotation |
X-axis label rotation |
n.breaks |
Number of breaks |
value.labels |
Show values in the bars. Use TRUE to include the labels in the bars. Use FALSE to not include them. |
position.value.labels |
Position of the values on the bars. Use "in" to display the labels inside the bars. Use "out" to display them outside the bars. |
size.value.labels |
Font size of the values in the bars |
A graph of the pyramid of population percentage
df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) df <- percDF(df, "gAge", "Sex", "Population") plotPercPyramid(df=df, age="gAge", sex="Sex", perpop="perc_Population", value.labels=FALSE)df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) df <- percDF(df, "gAge", "Sex", "Population") plotPercPyramid(df=df, age="gAge", sex="Sex", perpop="perc_Population", value.labels=FALSE)
Create a population pyramid graph
plotPyramid( df, age, sex, pop, labx = pop, laby = age, twocolors = c("#41ae76", "#ef6548"), rotation = 90, n.breaks = 20, value.labels = TRUE, position.value.labels = "in", size.value.labels = 3 )plotPyramid( df, age, sex, pop, labx = pop, laby = age, twocolors = c("#41ae76", "#ef6548"), rotation = 90, n.breaks = 20, value.labels = TRUE, position.value.labels = "in", size.value.labels = 3 )
df |
Name of dataframe |
age |
Age or age group. Write the parameter in quotation marks. |
sex |
Sex or other categorical grouping variable. Write the parameter in quotation marks. |
pop |
Population (in numerical value). Write the parameter in quotation marks. |
labx |
X-axis label |
laby |
Y-axis label |
twocolors |
Two colors for the pyramid |
rotation |
X-axis label rotation |
n.breaks |
Number of breaks |
value.labels |
Show values in the bars. Use TRUE to include the labels in the bars. Use FALSE to not include them. |
position.value.labels |
Position of the values on the bars. Use "in" to display the labels inside the bars. Use "out" to display them outside the bars. |
size.value.labels |
Font size of the values in the bars |
A population pyramid graph
df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) plotPyramid(df=df, age="gAge", sex="Sex", pop="Population", value.labels=FALSE)df <- popPyramid::popPER df <- dplyr::filter(df, Year==2021) plotPyramid(df=df, age="gAge", sex="Sex", pop="Population", value.labels=FALSE)
Peru population (1995-2030)
popPERpopPER
dataframe
chr Year
chr Sex
chr Age
chr Age group
dbl Population