Learn R Programming

capm (version 0.14.0)

PlotPopPyramid: 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

age.col

dat column that has a numeric vector representing ages or stage categories.

sex.col

dat column that has two unique values representing the sex of individuals (see Details).

str.col

dat column that has two unique values representing the reproductive status of individuals (see Details).

str.tip

string with the category of str.col to place at tip of the bars.

x.label

string to be used as a label for the x axis. If undefined, x.label is equal to "Total" (see Details).

stage.label

a string to be used as a label for the ages or stage categories. If undefined, stage.label is equal to "Years" (see Details).

legend.label

a string to be used as a label for the legend. If undefined, legend.label is equal to "Sterilized".

inner.color

any valid specification of a color. When str.col is not NULL, inner.color is the color of inner bars.

outer.color

any valid way specification of a color. When str.col is NULL, outer.color is the default color. When str.col is not NULL, outer.color is the outer color of bars.

label.size

string to define the font size for labels.

Value

Two opposed horizontal barplots.

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).

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

Run this code
# NOT RUN {
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")

# }

Run the code above in your browser using DataLab