[R] pyramid.plot: x-axis scale
Jim Lemon
jim at bitwrit.com.au
Thu Jul 30 14:37:33 CEST 2009
ws wrote:
> Hi R-ers
>
> Does anyone know how if there is a way to force pyramid plot where
> you determine the bottom axis range? I want to compare many
> different pyramids, so I am hoping to force the bottom axis range
> from 0% to 10%.
>
> Here is the code so far, if it matters:
>
> mk.pyr = function(data, pumas=NULL, fb.class=NULL, info="") {
> # Makes population pyramids
> # Assumes certain columns names in data -- SEX, AGEF, PUMA
>
> males.i = data$SEX==1
> females.i = data$SEX==1
>
> if (is.null(pumas)) {
> xy.pop = 100*as.double(prop.table(xtabs(pwgtp~AGEF,
> data[males.i,])))
> xx.pop = 100*as.double(prop.table(xtabs(pwgtp~AGEF,
> data[females.i,])))
> mytitle = sprintf("Population Pyramid for all pumas. %s.",
> info)
>
> } else {
> pumas.i = data$PUMA %in% pumas
> xy.pop = 100*as.double(prop.table(
> xtabs(pwgtp~AGEF, data[males.i & pumas.i,])))
> xx.pop = 100*as.double(prop.table(
> xtabs(pwgtp~AGEF, data[females.i & pumas.i ,])))
> mytitle = sprintf("Population Pyramid for %s",
> paste(paste(pumas, collapse=", "), ".", info, "."))
> }
> 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-44","85+")
> xycol<-color.gradient(.5,.5,.5,18)
> xxcol<-color.gradient(.5,.5,.5,18)
> par(mar=pyramid.plot(xy.pop,xx.pop,labels=agelabels,
> main=mytitle,xycol=xycol,xxcol=xxcol))
> }
>
>
Hi ws,
You could tweak pyramid.plot in the plotrix package to do this.
Jim
More information about the R-help
mailing list