PlotPopPyramid {capm} | R Documentation |
Population PlotPopPyramid
Description
Displays two opposed horizontal barplots (pyramid).
Usage
PlotPopPyramid(dat = NULL, age.col = NULL, sex.col = NULL,
str.col = NULL, str.tip = NULL, x.label = "Count",
stage.label = "Years", legend.label = "Sterilized",
inner.color = "LightBlue", outer.color = "DarkRed",
label.size = 13)
Arguments
dat |
|
age.col |
|
sex.col |
|
str.col |
|
str.tip |
string with the category of |
x.label |
string to be used as a label for the x axis. If undefined, |
stage.label |
a string to be used as a label for the ages or stage categories. If undefined, |
legend.label |
a string to be used as a label for the legend. If undefined, |
inner.color |
any valid specification of a color. When |
outer.color |
any valid way specification of a color. When |
label.size |
string to define the font size for labels. |
Details
PlotPopPyramid
is mainly intended for companion animals population pyramids, although it can display other types of opposed bar charts.
The bars to the left of the x axis correspond to sort(unique(dat[, sex.col]))[1]
. If str.col
is not NULL
, bars will be stacked, with sort(unique(dat[, str.col]))[1]
as their base.
On the top of the plot, it is displayed the total number of observations of each dat[, sex.col]
unique value. This unique values are used as labels
.
The legend labels
are equal to the dat[, str.col]
unique values.
Font size of saved plots is usually different to the font size seen in graphic browsers. Before changing font sizes, see the final result in saved (or preview) plots.
Other details of the plot can be modifyed using appropriate functions from ggplot2
package (see examples).
Value
Two opposed horizontal barplots.
Note
In companion animals population surveys, some age categories might be empty. One difference between PlotPopPyramid
and pryramid.plot
is that the first does not drop empty age categories.
References
Baquero, O. S., Marconcin, S., Rocha, A., & Garcia, R. D. C. M. (2018). Companion animal demography and population management in Pinhais, Brazil. Preventive Veterinary Medicine.
http://oswaldosantos.github.io/capm
Examples
data(dogs)
PlotPopPyramid(dogs,
age.col = "age",
sex.col = "sex",
str.col = "sterilized")
PlotPopPyramid(dogs,
age.col = "age",
sex.col = "sex")
## Merge age categories
pp_age <- cut(c(dogs$age, dogs$age3),
breaks = c(0, 1, 3, 5, 7, 9, 11, 13, 15,
max(c(dogs$age, dogs$age3), na.rm = TRUE)),
labels = c("<1", "1-3", "3-5", "5-7", "7-9",
"9-11", "11-13", "13-15", ">15"),
include.lowest = TRUE)
pp_sex <- c(dogs$sex, dogs$sex3)
pp_ster <- c(dogs$sterilized, dogs$sterilized3)
pp <- data.frame(age = pp_age, sex = pp_sex, sterilized = pp_ster)
PlotPopPyramid(pp,
age.col = "age",
sex.col = "sex",
str.col = "sterilized")
PlotPopPyramid(pp,
age.col = "age",
sex.col = "sex")