Skip to content
Prev 285821 / 398502 Next

barplot with more than 1 variable

On 02/19/2012 11:31 PM, Francesco Sarracino wrote:
Hi Francesco,
You can try this to get something like your example. change the "mar" 
argument to leave space for a legend and use par(xpd=TRUE) to put it 
outside the plot if you want a legend.

# first stretch the data out to long form
library(prettyR)
TUSE3<-rep_n_stack(TUSE2,to.stack=c("mw","st","all"),
  stack.names=c("work_type","output"))
# start a wide graphics device
x11(width=10)
library(plotrix)
# get the order of levels in work_type right
TUSE3$work_type<-factor(TUSE3$work_type,levels=c("mw","st","all"))
# display it as a nested bar plot
barNest(output~country+year3+work_type,TUSE3,showall=FALSE,
  FUN="mean",main="Type of work in 4 countries in two intervals",
  ylab="Value of work",
  barlabels=list("",c("Germany","Italy","Netherlands","United States"),
  c("1985-91","2000-03"),levels(TUSE3$work_type)),
  col=list("white","white","white",c("gray80","gray50","gray20")))

Jim