[R] Help with multiple barplots

Simon Kiss sjkiss at gmail.com
Thu Jan 31 16:42:52 CET 2013

Hello: I need to create a six barplots from data that looks pretty close to what appears below. There are two grouping variables (age and gender) and three dependent variables for each grouping variables.  I'm not really familiar with trellis graphics, perhaps there is something that can do what I need there, i don't know.  
The thing is: I *need* these to appear on one row, with some way of differentiating between the three barplots of one grouping variable and the three from the other grouping variable.  It's for a grant application and space is at a premium.  The width of everything can be about 7 inches wide and the height maybe 2 to 2.5 inches. I also need an outer margin to place a legend.  I can do this with the following using the layout command, but I cannot figure out a nice way to differentiate the two groups of variables.  I'd like to find a way to put a little bit of space between the three from one grouping variable and the three from another grouping variable.  

If anyone has any thoughts, I'd be very grateful. Yours truly, Simon J. Kiss

###Random Data
crime<-sample(c('agree' ,'disagree'), replace=TRUE, size=100)
guns<-sample(c('agree','disagree'), replace=TRUE, size=100)
climate<-sample(c('agree', 'disagree'), replace=TRUE, size=100)
gender<-sample(c('male','both' ,'female'), replace=TRUE, size=100)
age<-sample(c('old', 'neither', 'young'), replace=TRUE, size=100)
dat<-as.data.frame(cbind(crime, guns, climate, gender, age))
###Code I'm working with now
layout(matrix(c(1,2,3,4,5,6), c(1,6)))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$gender), 2))
barplot(prop.table(table(dat$climate, dat$gender), 2))
barplot(prop.table(table(dat$guns, dat$gender), 2))
barplot(prop.table(table(dat$crime, dat$age), 2))
barplot(prop.table(table(dat$climate, dat$age), 2))

More information about the R-help mailing list