Tomado de: http://www.demog.berkeley.edu/faq/faq.html#SECTION00421000000000000000 How can I draw a population pyramid Below is a chunk of R code that will draw a pretty nice population pyramid, please adapt it and improve it. ######################################################################## ## Sat Mar 9 20:21:19 PST 2002 ## Carlm's pretty good population pyramid function. ######################################################################## poppyr<-function(age.male,age.female,agecats=c(0,1,4,seq(5,100,5))){ ##age.male is a vector of ages of males, age.females is a vector of the ## mean batting averages of the New York Yankees, agecats is a ## vector of break points of ages -- defaults to a pretty standard ## one ## ## Will draw a pretty good but not quite perfect population pyramid male.ac<-table(cut(age.male,breaks=agecats)) female.ac<-table(cut(age.female,breaks=agecats)) ## 5/13/04 Megan Heller reports that some alternative 'figs' ## values can improve the appearance of the population pyramid ## by eliminating the space between the sexes. Here are ## Megan's suggested values: # ##this one looks best in terminal # split.screen(figs=rbind(c(0,.58,0,1),c(.43,1,0,1))) ## this one looks best in png (png files are the easiest to # import into MSWord -- not that you'd ever want to do that. # split.screen(figs=rbind(c(0,.58,0,1),c(.38,1,0,1))) split.screen(figs=rbind(c(0,.57,0,1),c(.45,1,0,1))) screen(1) barplot(female.ac,horiz=T,names=paste(agecats[-length(agecats)]), xlim=c(max(female.ac)*1.1,0),col="#FF9900") title("Female") screen(2) barplot(male.ac,horiz=T,axisnames=F, xlim=c(0,max(male.ac)*1.1),col="#0000FF") title("Male") close.screen(all=T) } age.male<-rnorm(10000)*50 age.female<-rnorm(10000)*50 poppyr(age.male,age.female) mtext(side=3,line=3,text="Population Pyramid",cex=1.5)