R Code‎ > ‎Lotka‎ > ‎


plot.R0DecompKitagawa {Lotka} R Documentation

a plot method for the output from an R0DecompKitagawa() decomposition.


This function recognizes the output from an R0DecompKitagawa() decomposition and plots it as stacked barplot()s. Three areas are depicted over each age, fertility, sex ratio, and survival. Includes legend and age labels with guidelines, as well as several default settings.


plot.R0DecompKitagawa(x, xlim = c(10, 60), col = c("#19B355", "#D8FD0C", "#DA1F04"), main, ylim, leg.pos = "topright")


x output from R0DecompKitagawa().
xlim the limits for the plot area, defined as c(xmin,xmax). R0DecompKitagawa output does not include a vector of ages; all vectors are assumed to start at zero and to be in single ages. The default value is c(0,60), which includes both pre- and post- reproductive ages for women. If dx==TRUE, then it is always good to have 0 as the left bound of the plot area, since infant mortality often accounts for large differences in R0.
col a vector specifying three colors, in order: Fertility, SRB, survival/mortality. Defaults to c("#19B355", "#D8FD0C", "#DA1F04"), green, yellow, red.
main title for the plot. Defaults to "R0 difference decomposition; R01 = x, R02 = x"
ylim A vector specifying the y axis limits for the plot area. Default values make use of pretty().
leg.pos text string indicating the legend position. Default = "topright". See type ?legend in the console for more info on other position options.


This plot method is not 100% flexible. To reproduce the basic scheme but with full control of graphical settings, see the code below for plotting ideas. The basic strategy is to rbind the three output vectors together that you wish to plot (Fert,SRB,Surv), and make two copies of this. In one copy, place only the positive values, with zeroes in all other elements. In the other copy place only the engative values with zeroes in all other elements. Then use barplot() twice for these two matrces, with add=TRUE the scond time. Plotting positives and negatives separately removes overlapping.


Timothy Riffe

See Also

See Also R0DecompKitagawa, summary.R0DecompKitagawa


# Fertility
fx2 <- LotkaData[,"Bx2"]/LotkaData[,"Nx2"]
fx1 <- LotkaData[,"Bx1"]/LotkaData[,"Nx1"]
# Proportion births female
px2 <- LotkaData[,"px2"]
px1 <- LotkaData[,"px1"]
# Proportion births female
Lx2 <- LotkaData[,"Lx2"]
Lx1 <- LotkaData[,"Lx1"]

DecompK <- R0DecompKitagawa(fx1,px1,Lx1,fx2,px2,Lx2)

## The function is currently defined as
if (missing(main)){
main <- paste("R0 difference decomposition; R01 = ",round(x$R01,digits=4),", R02 = ",round(x$R02,digits=4))
# age range to be plotted
age <- xlim[1]:xlim[2]
Epsilon <- rbind(x$Fert[(age+1)],x$SRB[(age+1)],x$Surv[(age+1)])
leg <- c(paste("Fertility",round(sum(x$Fert),4)),paste("SRB ",round(sum(x$SRB),4)),paste("Survival ",round(sum(x$Surv),4)))

EPSpos <- Epsilon * .5*(sign(Epsilon)+1)
EPSneg <- Epsilon * .5*abs(sign(Epsilon)-1)

# ylim (for looping)
if (missing(ylim)){
ylim <- range(pretty(c(EPSpos,EPSneg)))
ymax <- ylim[2]
ymin <- ylim[1]
barplot(EPSpos,space=0,col=col,ylab="contrib to diff in R0",xlab="age",main=main,ylim=ylim)

[Package Lotka version 1.1 Index]