m1950<-c(8236164,6714555,5660399,5311342,5606293,5972078,5624723,5517544,5070269,4526366,4128648,3630046,3037838,2424561,1628829,1001798,504958,236828);
m2000<-c(9810733,10523277,10520197,10391004,9687814,9798760,10321769,11318696,11129102,9889506,8607724,6508729,5136627,4400362,3902912,3044456,1834897,1226998);
f1950<-c(7927407,6485130,5458869,5305256,5875535,6270182,5892284,5728842,5133704,4544099,4143540,3605074,3021637,2578375,1783120,1150609,620386,340073);
f2000<-c(9365065,10026228,10007875,9828886,9276187,9582576,10188619,11387968,11312761,10202898,8977824,6960508,5668820,5133183,4954529,4371357,3110470,3012589);
GPS<-18;
ma1950<-matrix(0,1,GPS); ma2000<-matrix(0,1,GPS);
fa1950<-matrix(0,1,GPS); fa2000<-matrix(0,1,GPS);
ma1950p<-m1950/sum(m1950+f1950); fa1950p<-f1950/sum(m1950+f1950);
ma2000p<-m2000/sum(m2000+f2000); fa2000p<-f2000/sum(m2000+f2000);
## Year 1950
xy.pop<-t(ma1950p); xx.pop<-t(fa1950p);
## Year 2000
xy.pop2<-t(ma2000p); xx.pop2<-t(fa2000p);
##Put things together
library(plotrix);
males<-matrix(0, GPS,2);
males[,1]<-xy.pop; males[,2]<-xy.pop2;
females<-matrix(0,GPS,2)
females[,1]<-xx.pop; females[,2]<-xx.pop2;
agelabels<-c("0-4","5-9", "10-14","15-19", "20-24", "25-29",
"30-34","35-39", "40-44","45-49", "50-54",
"55-59","60-64", "65-69", "70-74","75-79",
"80-84","85+");
##postscript("pyramidUSPop.eps")
myPyramid<-pyramid.plot(males*100,females*100,labels=agelabels,
lxcol=c("blue","green"),
rxcol=c("blue","green"),
laxlab=seq(0,10,by=2), raxlab=seq(0,10,by=2),
top.labels=c("Males","Age","Females"),
gap=3);
mtext("US population by age and gender",3,2,cex=1.5);
legend(par("usr")[1],GPS,c("1950","2000"), fill=c("blue","green"));
## To restore the margins and background
par(mar=myPyramid,bg="transparent");