Population PlotPopPyramid

Share:

Description

Display 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

the number or name of dat column which have a numeric vector representing ages or stage categories.

sex.col

the number or name of dat column which have a factor with two levels representing the sex of individuals (see Details).

str.col

the number of dat column which have a factor representing the reproductive status of individuals (see Details).

x.label

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

stage.label

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

legend.label

a string to be used as a label for the legend. If not defined, 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 with suitable modification of the arguments.

The bars to the left of 0 on the x axis correspond to the minimum value of as.numeric (dat[, sex.col]). If str.col is not NULL, bars will be stacked, with the minimum value of as.numeric(dat[, str.col]) as their base.

On the top of the plot, it is displayed the total number of observations of each level of dat[, sex.col]. The levels of sex.col are used as labels.

The legend labels are equal to the levels of dat[, str.col].

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
## Load data with information about age, sex and reproductive status of individuals.
data(survey.data)
# Uncomment the following lines:
# PlotPopPyramid(survey.data, age.col = 5, sex.col = 4, str.col = 6)
# PlotPopPyramid(survey.data, age.col = 5, sex.col = 4)