popPyramid is a package that facilitates the elaboration of population pyramids.
Install popPyramid from CRAN:
install.packages("popPyramid")
or install popPyramid with
library(remotes)
install_github("musajajorge/popPyramid")
Using the default parameters.
df <- popPyramid::popPER
df <- dplyr::filter(df, Year==2021)
library(popPyramid)
plotPyramid(df=df, age="gAge", sex="Sex", pop="Population")
Modifying the colors, X and Y axis labels, as well as the rotation of the X axis labels.
df <- popPyramid::popPER
df <- dplyr::filter(df, Year==2021)
library(popPyramid)
plotPyramid(df=df, age="gAge", sex="Sex", pop="Population",
labx="Personas", laby="Grupo de edad",
twocolors=c("steelblue","violetred3"),
rotation=45, n.breaks=15, value.labels=FALSE)
Modifying the position of the values in the bars.
df <- popPyramid::popPER
df <- dplyr::filter(df, Year==2021)
library(popPyramid)
plotPyramid(df=df, age="gAge", sex="Sex", pop="Population",
value.labels=TRUE, position.value.labels = "out",
size.value.labels=4)
Using the default parameters.
df <- popPyramid::popPER
df <- dplyr::filter(df, Year==2021)
df <- percDF(df, "gAge", "Sex", "Population")
library(popPyramid)
plotPercPyramid(df=df, age="gAge", sex="Sex", perpop="perc_Population")
Modifying the position of the values on the bars, the X and Y axis labels and the colors of the bars.
df <- popPyramid::popPER
df <- dplyr::filter(df, Year==2021)
df <- percDF(df, "gAge", "Sex", "Population")
library(popPyramid)
plotPercPyramid(df=df, age="gAge", sex="Sex", perpop="perc_Population",
labx="% Personas", laby="Grupo de edad", n.breaks=10,
twocolors=c("steelblue","violetred3"),
value.labels=TRUE, position.value.labels="out",
size.value.labels=4)