I tried to create a multiple grouped bar chart but I haven't figured out how to get the right layout. I have created one which shows at least the right thing but the bars are vertical instead of horizontal.
Code:
sex <- c('F', 'F', 'F', 'F', 'F','M','M','M','M')
type <-c('XL1','XL1','XL1','XL2','XL2','XL2','XL2','XL2','XL2')
ID <- c(1,2,3,4,5,6,7,8,9)
smoke <- c('yes','yes','no','yes','no','yes','no','no','yes')
improved <- c(12,9.8,13,4,7,9,6.5,12.2,-1)
dat <- as.data.frame(cbind(sex,type,ID,smoke,improved))
base <- ggplot(dat, aes(fill = interaction(sex,type,smoke))) +
geom_bar(position = 'dodge',stat='identity')
base + aes(x = factor(ID), y=improved) +
facet_grid(.~type+sex, scales = "free_x", space = "free")
The problem is that I have another grouping variable except type and sex and all three have in the real dataset long labels. I could rotate them by 90 degrees but I prefer to rotate the whole graph by 90 degrees and flip_coord() doesn't work... The solution mentioned at the end of this thread isn't really nice. Also because the grouping variables are on the right and not on the left.
I'm grateful for any advice. Thanks,
Anja