[R] pyramid.plot in plotrix, axis labelling

Jim Lemon jim at bitwrit.com.au
Thu Apr 12 22:37:16 CEST 2012


On 04/12/2012 09:55 PM, Gavin Rudge wrote:
> Hi, I've been looking at ways to make pyramid plots in R.  I like the pyramid.plot method in plotrix as it seems the simplest to use and building them in ggplot looks a bit more code intensive than I'd like, being as I'm new to R.  This package does pretty much what I need it to do, however I can't seem to scale the x axis labels.  The other labels scale fine with labelcex.
>
> I guess the preferred method is to remove them and re-build them as you might in the base package, but I have no idea how to refer to them as there are two of them.
>
> I have enclosed some sample data lifted from another example.  I've scaled down the other labels using labelcex whch leaves the disparity in sizes that I'm trying to remove.  I'd like something like this but with the x axis lables the same size as the y.
>
>
>> mpop=c(50,75,80,100,110,90,85,60,40,20)
>> fpop=c(50,75,80,100,110,90,85,60,50,30)
>> coh=c("0-9","10-19","20-29","30-39","40-49","50-59","60-69","70-79","80-89","90-99")
>> pyramid.plot(mpop,fpop,labels=coh,gap=15,labelcex=0.7,top.labels=c("males","age group","females"),lxcol="red",rxcol="blue", laxlab=c(0,50,100,150),raxlab=c(0,50,100,150))
>
>
Hi Gavin,
Just change line 23 in the function from:

par(mar=ppmar)

to:

par(mar=ppmar,cex.axis=labelcex)

This will be in the next version of plotrix. Thanks for the heads-up.

Jim



More information about the R-help mailing list