R barplot beside and stacked

Viewed 739

I try to create a barplot, that uses besides and stacked at the same time. I have something that is similar to what I want with facet:

Similar to the searched feature

tmp <- morley
tmp$loc <- paste("No", tmp$Run %/% 2, sep="")
tmp$group <- as.logical(tmp$Run %% 2)
tmp$year <- tmp$Expt + 2000
tmp$value <- tmp$Speed
tmp <- subset(tmp, loc %in% c("No1", "No2", "No3"))

ggplot(tmp, aes(x=loc, y=value, fill=group)) + 
  geom_bar(stat ='identity', position ='stack') + 
  facet_grid (~year)

I would want that without facets and 2 legends (Green: No1, Red: No2, Blue: No3 and TRUE: 0% transparency, FALSE 40% transparency) with the years on the x-axis, the locations beside and the groups stacked. Also a legend with 6 entries No1 true, No1 false, No2 true... would be okay.

Is there a way to do this?

1 Answers
ggplot(tmp, aes(x=loc, y=value, fill=loc, alpha=group)) + 
  geom_bar(stat ='identity', position ='stack') +
  scale_alpha_manual(values=c('TRUE'=1, 'FALSE'=0.6)) +
  facet_grid(~year, switch='x') +
  theme(axis.title.x=element_blank(), strip.placement='outside')

And then adjust themes and fill scale appropriately.

enter image description here

Related