# pop.trajectories.plot: Output of Probabilistic Population Projection In bayesPop: Probabilistic Population Projection

## Description

The functions plot and tabulate the distribution of population projection for a given country, or for all countries, including the median and given probability intervals.

## Usage

 ``` 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``` ```pop.trajectories.plot(pop.pred, country = NULL, expression = NULL, pi = c(80, 95), sex = c("both", "male", "female"), age = "all", sum.over.ages = FALSE, half.child.variant = FALSE, nr.traj = NULL, typical.trajectory = FALSE, main = NULL, dev.ncol = 5, lwd = c(2, 2, 2, 2, 1), col = c("black", "red", "red", "blue", "#00000020"), show.legend = TRUE, ann = par("ann"), ...) pop.trajectories.plotAll(pop.pred, output.dir=file.path(getwd(), "pop.trajectories"), output.type="png", expression = NULL, verbose=FALSE, ...) pop.trajectories.table(pop.pred, country = NULL, expression = NULL, pi = c(80, 95), sex = c("both", "male", "female"), age = "all", half.child.variant = FALSE, ...) pop.byage.plot(pop.pred, country = NULL, year = NULL, expression = NULL, pi = c(80, 95), sex = c("both", "male", "female"), half.child.variant = FALSE, nr.traj = NULL, typical.trajectory=FALSE, xlim = NULL, ylim = NULL, xlab = "", ylab = "Population projection", main = NULL, lwd = c(2,2,2,1), col = c("red", "red", "blue", "#00000020"), show.legend = TRUE, add = FALSE, ann = par("ann"), type = "l", pch = NA, pt.cex = 1, ...) pop.byage.plotAll(pop.pred, output.dir=file.path(getwd(), "pop.byage"), output.type="png", expression = NULL, verbose=FALSE, ...) pop.byage.table(pop.pred, country = NULL, year = NULL, expression = NULL, pi = c(80, 95), sex = c("both", "male", "female"), half.child.variant = FALSE) ```

## Arguments

 `pop.pred` Object of class `bayesPop.prediction`. `country` Name or numerical code of a country. `expression` Expression defining the population measure to be plotted. For syntax see `pop.expressions`. For `pop.trajectories.plot`, `pop.trajectories.table`, `pop.byage.plot` and `pop.byage.table` the basic components of the expression must be country-specific. For `pop.trajectories.plotAll` and `pop.byage.plotAll` the country part should be given as “XXX”. In addition, expressions passed into `pop.byage.plot` and `pop.byage.table` must contain curly braces (i.e. be age specific). `pi` Probability interval. It can be a single number or an array. `sex` One of “both” (default), “male” or “female”. By default the male and female projections are summed up. `age` Either a character string “all” (default) or an integer vector of age indices. Value 1 corresponds to age 0-4, value 2 corresponds to age 5-9 etc. Last age goup 130+ corresponds to index 27. It can also be the string “psr” (potential support ratio), in which case a ratio of population of ages 20-64 to 65+ (indices 5:13 to 14:27) is shown. `sum.over.ages` Logical. If `TRUE`, the values are summed up over given age groups. Otherwise there is a separate plot for each age group. `half.child.variant` Logical. If TRUE the United Nations “+/-0.5 child” variant computed with fertility +/- 0.5* TFR median and the median of life expectancy is shown. `nr.traj` Number of trajectories to be plotted. If `NULL`, all trajectories are plotted, otherwise they are thinned evenly. `typical.trajectory` Logical. If `TRUE` one trajectory is shown that has the smallest distance to the median. `xlim, ylim, xlab, ylab, main, ann, pt.cex` Graphical parameters passed to the `plot` function. `dev.ncol` Number of column for the graphics device if `sum.over.ages` is `FALSE`. If the number of age groups is smaller than `dev.ncol`, the number of columns is automatically decreased. `lwd, col` For the first three functions it is a vector of five elements giving the line width and color for: 1. observed data, 2. median, 3. quantiles, 4. half-child variant, 5. trajectories. For functions that show results by age it is a vector of four elements - as above without the first item (observed data). `type, pch` Currently works for plotting by age only. It is a vector of four elements giving the plot type and point type for: 1. median, 2. quantiles, 3. half-child variant, 4. trajectories. The last element of the array is recycled. `show.legend` Logical controlling whether the legend should be drawn. `...` Additional graphical arguments. Functions `pop.trajectories.plotAll` and `pop.byage.plotAll` accept also any arguments of `pop.trajectories.plot` and `pop.byage.plot`, respectively, except `country`. `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”. `verbose` Logical switching log messages on and off. `year` Any year within the time period to be outputted. `add` Logical specifying if the plot should be added to an existing graphics.

## Details

`pop.trajectories.plot` plots trajectories of population projection by time for a given country.
`pop.trajectories.table` gives the same output as a table. `pop.trajectories.plotAll` creates a set of graphs (one per country) that are stored in `output.dir`. The projections can be visualized separately for each sex and age groups, or summed up over both sexes and/or given age groups. This is controlled by the arguments `sex`, `age` and `sum.over.ages`.

`pop.byage.plot` and `pop.byage.table` plots/tabulate the posterior distribution by age for a given country and time period. `pop.byage.plotAll` creates such plots for all countries.

The median and given probability intervals are computed using all available trajectories. Thus, `nr.traj` does not influence those values - it is used only to control the number of trajectories plotted.

If plotting results of an expression and the function fails, to debug obtain values of that expression using the functions `get.pop.ex` (for `pop.trajectories.plot`) and `get.pop.exba` (for `pop.byage.plot`).

## Author(s)

Hana Sevcikova

`bayesPop.prediction`, `summary.bayesPop.prediction`, `pop.pyramid`, `pop.expressions`, `get.pop`

## Examples

 ```1 2 3 4 5 6 7 8 9``` ```sim.dir <- file.path(find.package("bayesPop"), "ex-data", "Pop") pred <- get.pop.prediction(sim.dir) pop.trajectories.plot(pred, country="Ecuador", pi=c(80, 95)) pop.trajectories.table(pred, country="Ecuador", pi=c(80, 95)) # female population of Ecuador in child bearing ages (by time) pop.trajectories.plot(pred, expression="PEC_F[4:10]") # Population by age in Netherands for two different years pop.byage.plot(pred, country="Netherlands", year=2050) pop.byage.plot(pred, expression="PNL{}", year=2000) ```

### Example output

```Loading required package: bayesTFR
Creating a generic function for 'toJSON' from package 'jsonlite' in package 'googleVis'
median    0.025      0.1      0.9    0.975
1950  3470.162       NA       NA       NA       NA
1955  3957.482       NA       NA       NA       NA
1960  4545.548       NA       NA       NA       NA
1965  5250.120       NA       NA       NA       NA
1970  6072.520       NA       NA       NA       NA
1975  6987.393       NA       NA       NA       NA
1980  7976.449       NA       NA       NA       NA
1985  9045.977       NA       NA       NA       NA
1990 10218.085       NA       NA       NA       NA
1995 11440.576       NA       NA       NA       NA
2000 12628.596       NA       NA       NA       NA
2005 13735.232       NA       NA       NA       NA
2010 14934.692       NA       NA       NA       NA
2015 16144.363 16144.36 16144.36 16144.36 16144.36
2020 17336.758 17179.69 17204.49 17469.32 17494.17
2025 18481.167 18062.04 18128.22 18835.17 18901.54
2030 19561.041 18803.38 18923.01 20201.56 20321.65
2035 20565.874 19451.64 19627.58 21514.30 21692.13
2040 21480.961 19974.03 20211.97 22786.40 23031.17
2045 22295.965 20346.35 20654.18 24029.59 24354.64
2050 23006.226 20563.27 20949.00 25242.34 25661.61
2055 23605.104 20628.07 21098.13 26407.72 26933.20
2060 24095.722 20555.44 21114.44 27519.33 28161.26
2065 24477.378 20352.84 21004.08 28574.24 29342.40
2070 24751.943 20025.35 20771.65 29577.49 30482.28
2075 24919.377 19574.95 20418.80 30531.14 31583.35
2080 24990.656 19014.23 19957.88 31446.09 32656.49
2085 24965.819 18348.27 19393.14 32318.45 33697.06
2090 24862.382 17600.10 18746.77 33162.38 34718.63
2095 24696.064 16791.69 18039.75 33990.68 35733.42
2100 24479.372 15942.63 17290.53 34812.33 36749.76
```

bayesPop documentation built on July 2, 2020, 3 a.m.