Description Usage Arguments Details Value Author(s) See Also Examples

Functions for plotting probabilistic population pyramid. `pop.pyramid`

creates a classic pyramid using rectangles; `pop.trajectories.pyramid`

creates one or more pyramids using vertical lines (possibly derived from population trajectories). They can be used to view a prediction object created with this package, or any user-defined sex- and age-specific dataset. For the latter, function `get.bPop.pyramid`

should be used to translate user-defined data into a `bayesPop.pyramid`

object.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | ```
## S3 method for class 'bayesPop.prediction'
pop.pyramid(pop.object, country, year = NULL,
indicator = c("P", "B", "D"), pi = c(80, 95),
proportion = FALSE, age = 1:21, plot = TRUE, pop.max = NULL, ...)
## S3 method for class 'bayesPop.pyramid'
pop.pyramid(pop.object, main = NULL, show.legend = TRUE,
pyr1.par = list(border="black", col=NA, density=NULL, height=0.9),
pyr2.par = list(density = -1, height = 0.3),
col.pi = NULL, ann = par("ann"), axes = TRUE, grid = TRUE,
cex.main = 0.9, cex.sub = 1, cex = 1, cex.axis = 1, ...)
pop.pyramidAll(pop.pred, year = NULL,
output.dir = file.path(getwd(), "pop.pyramid"),
output.type = "png", one.file = FALSE, verbose = FALSE, ...)
## S3 method for class 'bayesPop.prediction'
pop.trajectories.pyramid(pop.object, country, year = NULL,
indicator = c("P", "B", "D"), pi = c(80, 95), nr.traj = NULL,
proportion = FALSE, age = 1:21, plot = TRUE, pop.max = NULL, ...)
## S3 method for class 'bayesPop.pyramid'
pop.trajectories.pyramid(pop.object, main = NULL, show.legend = TRUE,
col = rainbow, col.traj = "#00000020", lwd = 2, ann = par("ann"), axes = TRUE,
grid = TRUE, cex.main = 0.9, cex.sub = 1, cex = 1, cex.axis = 1, ...)
pop.trajectories.pyramidAll(pop.pred, year = NULL,
output.dir = file.path(getwd(), "pop.traj.pyramid"),
output.type = "png", one.file = FALSE, verbose = FALSE, ...)
## S3 method for class 'bayesPop.pyramid'
plot(x, ...)
## S3 method for class 'bayesPop.prediction'
get.bPop.pyramid(data, country, year = NULL,
indicator = c("P", "B", "D"), pi = c(80, 95),
proportion = FALSE, age = 1:21, nr.traj = 0, sort.pi=TRUE, pop.max = NULL, ...)
## S3 method for class 'data.frame'
get.bPop.pyramid(data, main.label = NULL, legend = "observed",
is.proportion = FALSE, ages = NULL, pop.max = NULL,
LRmain = c("Male", "Female"), LRcolnames = c("male", "female"), CI = NULL, ...)
## S3 method for class 'matrix'
get.bPop.pyramid(data, ...)
## S3 method for class 'list'
get.bPop.pyramid(data, main.label = NULL, legend = NULL, CI = NULL, ...)
``` |

`pop.object` |
Object of class |

`pop.pred` |
Object of class |

`x` |
Object of class |

`data` |
Data frame, matrix, list or object of class |

`country` |
Name or numerical code of a country. |

`year` |
Year within the projection or estimation period to be plotted. Default is the start year of the prediction. It can also be a vector of years. |

`indicator` |
One of the characters “P” (population), “B” (births), “D” (deaths) determining the pyramid indicator. |

`pi` |
Probability interval. It can be a single number or an array. |

`proportion` |
Logical. If |

`age` |
Integer vector of age indices. Value 1 corresponds to age 0-4, value 2 corresponds to age 5-9 etc. Last available age goup is 130+ which corresponds to index 27. The purpose of this argument here is mainly to control the height of the pyramid. |

`plot` |
If |

`main` |
Titel of the plot. By default it is the country name and projection year if known. |

`show.legend` |
Logical controlling if the plot legend is drawn. |

`pyr1.par, pyr2.par` |
List of graphical parameters (color, border, density and height) for drawing the pyramid rectangles, for the first and second pyramid, respectively (see Details). The |

`col.pi` |
Vector of colors for drawing the probability boxes. If it is given, it must be of the same length as |

`ann` |
Logical controlling if any annotation (main and legend) is plotted. |

`axes` |
Logical controlling if axes are plotted. |

`grid` |
Logical controlling if grid lines are plotted. |

`cex.main, cex.sub, cex, cex.axis` |
Magnification to be used for the title, secondary titles on the right and left panels, legend and axes, respectively. |

`output.dir` |
Directory into which resulting graphs are stored. |

`output.type` |
Type of the resulting files. It can be “png”, “pdf”, “jpeg”, “bmp”, “tiff”, or “postscript”. |

`one.file` |
Logical. If |

`verbose` |
Logical switching log messages on and off. |

`nr.traj` |
Number of trajectories to be plotted. If |

`col` |
Colors generating function. It is called with an argument giving the number of pyramids to be plotted. Each color is then used for one pyramid, including its confidence intervals. |

`col.traj` |
Color used for trajectories. If more than one pyramid is drawn with its trajectories, this can be a vector of the size of number of pyramids. |

`lwd` |
Line width for the pyramids. |

`sort.pi` |
Logical controlling if the probability intervals are sorted in decreasing order. This has an effect on the order in which they are plotted and thus on overlapping of pyramid boxes. By default the largest intervals are plotted first. |

`main.label` |
Optional argument for the main title. |

`legend` |
Legend to be used. In case of multiple pyramids, this can be a vector for each of them. If not given and |

`is.proportion` |
Either logical, indicating if the values in |

`ages` |
Vector of age labels. It must be of the same length as the number of rows of |

`pop.max` |
Maximum value to be drawn in the pyramid. If it is not given, |

`LRmain` |
Vector of character strings giving the secondary titles for the left and right panel, respectively. |

`LRcolnames` |
Vector of character strings giving the column names of data to be used for the left and right panel of the pyramid, respectively. |

`CI` |
Confidence intervals. It should be of the same format as the |

`...` |
Arguments passed to the underlying functions. |

The `pop.pyramid`

function generates one or two population pyramids in one plot. The first (main) one is usually the median of a future year prediction, but it can also be the current year or any population estimates. The second one serves the purpose of comparing two pyramids with one another and is drawn on top of the main pyramid. For example, one can use it to compare a future prediction with the present, or two different time points in the past, or two different geographies. The main pyramid can have confidence intervals associated with it, which are also plotted. If `pop.pyramid`

is called on a `bayesPop.prediction`

object, the main and secondary pyramid, respectively, is generated from data of a time period given by the first and second element, respectively, of the `year`

argument. In such a case, confidence intervals only of the first year are shown. Thus, it makes sense to set the first year to be a prediction year and the second year to an observed time period. If `pop.pyramid`

is called on a `bayesPop.pyramid`

object, data in the first and second element, respectively, of the `bayesPop.pyramid$pyramid`

list are used, and only the first element of `bayesPop.pyramid$CI`

is used.

Pyramids generated via the `pop.trajectories.pyramid`

function have different appearance and therefore more than two pyramids can be put into one figure. Furthermore, confidence intervals of more than one pyramid can be shown. Thus, all elements of `bayesPop.pyramid$pyramid`

and `bayesPop.pyramid$CI`

are plotted. In addition, single trajectories given in `bayesPop.pyramid$trajectories`

can be shown by setting the argument `nr.traj`

larger than 0.

Both, `pop.pyramid`

and `pop.trajectories.pyramid`

(if called with a `bayesPop.prediction`

object) use data from one country.
Functions `pop.pyramidAll`

and `pop.trajectories.pyramidAll`

create such pyramids for all countries for which a projection is available and for all years given by the `year`

argument which should be a list. In this case, one pyramid figure (possibly containing multiple pyramids) is created for each country and each element of the `year`

list.

The core of these functions operates on a `bayesPop.pyramid`

object which is automatically created when called with a `bayesPop.prediction`

object. If used with a user-defined data set, one has to convert such data into `bayesPop.pyramid`

using the function `get.bPop.pyramid`

(see an example below). In such a case, one can simply use the `plot`

function which then calls `pop.pyramid`

.

`pop.pyramid`

, `pop.trajectories.pyramid`

and `get.bPop.pyramid`

return an object of class `bayesPop.pyramid`

which is a list with the following components:

`label` |
Label used for the main titel. |

`pyramid` |
List of pyramid data, one element per pyramid. Each component is a data frame with at least two columns, containing data for the left and right panels of the pyramid. Their names must correspond to |

`CI` |
List of lists of confidence intervals with one element per pyramid. The order corresponds to the order in the |

`trajectories` |
List of lists of trajectories with one element per pyramid. As in the case of |

`is.proportion` |
Logical indicating if values in the various data frames in this object are proportions or raw values. |

`pop.max` |
Maximum value for the x-axis. |

`LRmain` |
Vector of character strings determining the titles for the left and right panels, respectively. |

`LRcolnames` |
Vector of character strings determining the column names in |

Hana Sevcikova, Adrian Raftery, using feedback from Sam Clark and the bayesPop group at the University of Washington.

`pop.trajectories.plot`

, `bayesPop.prediction`

, `summary.bayesPop.prediction`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ```
# pyramids for bayesPop prediction objects
##########################################
sim.dir <- file.path(find.package("bayesPop"), "ex-data", "Pop")
pred <- get.pop.prediction(sim.dir)
pop.pyramid(pred, "Netherlands", c(2045, 2010))
dev.new()
pop.trajectories.pyramid(pred, "Netherlands", c(2045, 2010, 1960), age=1:25, proportion=TRUE)
# using manual manipulation of the data: e.g. show only the prob. intervals
pred.pyr <- get.bPop.pyramid(pred, country="Ecuador", year=2090, age=1:27)
pred.pyr$pyramid <- NULL
plot(pred.pyr)
# pyramids for user-defined data
################################
# this example dataset contains population estimates for the Washington state and King county
# (Seattle area) in 2011
data <- read.table(file.path(find.package("bayesPop"), "ex-data", "popestimates_WAKing.txt"),
header=TRUE, row.names=1)
# extract data for two pyramids and put it into the right format
head(data)
WA <- data[,c("WA.male", "WA.female")]; colnames(WA) <- c("male", "female")
King <- data[,c("King.male", "King.female")]; colnames(King) <- c("male", "female")
# create and plot a bayesPop.pyramid object
pyramid <- get.bPop.pyramid(list(WA, King), legend=c("Washington", "King"))
plot(pyramid, main="Population in 2011", pyr2.par=list(height=0.7, col="violet", border="violet"))
# show data as proportions
pyramid.prop <- get.bPop.pyramid(list(WA, King), is.proportion=NA, legend=c("Washington", "King"))
pop.pyramid(pyramid.prop, main="Population in 2011 (proportions)",
pyr1.par=list(col="lightgreen", border="lightgreen", density=30),
pyr2.par=list(col="darkred", border="darkred", density=50))
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.