PlotPopPyramid: Population PlotPopPyramid

Description Usage Arguments Details Value Note References Examples

View source: R/PlotPopPyramid.R

Description

Displays two opposed horizontal barplots (pyramid).

Usage

1
2
3
4
PlotPopPyramid(dat = NULL, age.col = NULL, sex.col = NULL,
  str.col = NULL, x.label = "Total", stage.label = "Years",
  legend.label = "Sterilized", inner.color = "Gold2",
  outer.color = "DarkOliveGreen", label.size = 13)

Arguments

dat

data.frame.

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

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 way to specify colors. When str.col is NULL, inner.color is the color of bars. When str.col is not NULL, innercolor is the inner color of bars. If non defined, inner.color is equal to "Gold2".

outer.color

any valid way to specify colors. When str.col is NULL, outer.color is ignored. When str.col is not NULL, outer.color is the outer color of bars. If non defined, outercolor is equal to "DarkOliveGreen".

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

http://oswaldosantos.github.io/capm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(cluster_sample_animals)
dogs <- cluster_sample_animals[complete.cases(cluster_sample_animals), ]
dogs <- dogs[dogs$species == "dog", ]
PlotPopPyramid(dogs,
               age.col = "age",
               sex.col = "sex",
               str.col = "sterilized")
PlotPopPyramid(dogs,
               age.col = "age",
               sex.col = "sex")

capm documentation built on May 29, 2017, 12:34 p.m.