[R] Single plot multiple levels in x?
Jim Lemon
jim at bitwrit.com.au
Fri Aug 31 10:48:09 CEST 2007
Richard Yanicky wrote:
>
>One axis inside another, for example salary within state,
>
>
>
>
>1-50 | 50 – 100 | 100+ | 1- 50 | 50 -100 | 100+ | … repeated bins for salary
> AL ! AR …… more states
Okay, I see what you mean. Try this:
rydf<-data.frame(
states=sample(c("NSW","QLD","VIC"),100,TRUE),
salaries=20000*(rnorm(100)+4))
nswdist<-hist(rydf$salaries[rydf$states=="NSW"],plot=FALSE,
breaks=c(0,50000,100000,150000))$counts
qlddist<-hist(rydf$salaries[rydf$states=="QLD"],plot=FALSE,
breaks=c(0,50000,100000,150000))$counts
vicdist<-hist(rydf$salaries[rydf$states=="VIC"],plot=FALSE,
breaks=c(0,50000,100000,150000))$counts
library(plotrix)
barp(c(nswdist,qlddist,vicdist),col=rep(2:4,each=3),
main="Salary distribution by state",
names.arg=rep("",9),ylab="Frequency")
staxlab(at=1:9,labels=rep(c("0-50K","50-100K","100-150K"),3))
mtext(c("NSW","QLD","VIC"),side=1,line=3,at=c(2,5,8))
and it is a great boon to R-helpers to have data, even fake like the above.
Jim
More information about the R-help
mailing list