if (!require(wpp2019)) { install.packages("wpp2019", dep=TRUE); library(wpp2019) } data(tfr) data(percentASFR) # TFR2015 <- tfr[, c("name","2015-2020")] # pASFR2015 <- percentASFR[, c("name","age","2015-2020")] # x <- merge(TFR2015, pASFR2015, by="name") # names(x) <- c("name", "tfr", "age", "pASFR") # x$ASFR <- x$tfr*x$pASFR/100 # y <- reshape(x[,c(1,3,5)], idvar="name", direction="wide", timevar="age") # matplot(t(y[, 2:8]*1000/5), type="l", lty=1, col="gray", # axes=F, ylab="ASFR2015-2020", main="World Fertilities 2015-2020") # axis(1, 1:7, sprintf("%d-%d", 3:9*5, 3:9*5+4)) # axis(2, 0:7*50, 0:7*50) SY <- 1950+0:13*5 EY <- 1955+0:13*5 TFRFrance <- tfr[tfr$name=="France", sprintf("%4d-%4d", SY, EY)] pASFRFrance <- percentASFR[percentASFR$name=="France", c("age", sprintf("%4d-%4d", SY, EY))] ASFRFrance <- pASFRFrance for (i in 0:13) { ASFRFrance[, i+2] <- pASFRFrance[, i+2]/100*TFRFrance[1, i+1] } matplot(ASFRFrance[, 2:15], type="b", ylim=c(0, 1), lty=1:7, pch=1:4, col=topo.colors(14), lwd=c(rep(1,7), rep(2,7)), axes=FALSE, xlab="age", ylab="ASFR", main="ASFR in France from 1950-55 to 2015-20") axis(1, 1:7, sprintf("%d-%d", 3:9*5, 3:9*5+4)) axis(2, 0:5/5, 0:5/5) legend("topright", lty=1:7, pch=1:4, col=topo.colors(14), lwd=c(rep(1,7), rep(2,7)), legend=sprintf("%4d-%4d", SY, EY))