library(pyramid) # x <- read.delim("http://minato.sip21c.org/demography/smallpop.txt") x <- read.delim("./smallpop.txt") # calculate 10 year age classes for each individual x$AC1960 <- cut(x$A1960, 0:10*10, right=FALSE) x$AC1980 <- cut(x$A1980, 0:10*10, right=FALSE) # calculate numbers from age for each individual PP1960 <- xtabs(~AC1960+SEX, data=x) PP1980 <- xtabs(~AC1980+SEX, data=x) # define custom wrapper function pmd <- function(TBL, YR, ...) { pyramids(Left=TBL[, 2], Right=TBL[, 1], Center=rownames(TBL), Cadj=0, Llab="Females", Rlab="Males", Clab="", GL=FALSE, ...) text(-1, 0.8, YR, cex=1.5, pos=4) } png("./smallpops.png", width=720, height=400, pointsize=9) layout(t(1:2)) pmd(PP1960, YR="1960", main="Changes of population structure by 20 yrs") pmd(PP1980, YR="1980") dev.off()