Folded columns in a grouped histogram

I have the following chart

test <- expand.grid('cat' = LETTERS[1:5], 'cond'= c(F,T), 'year' = 2001:2005) test$value <- floor((rnorm(nrow(test)))*100) test$value[test$value < 0] <- 0 ggplot() + geom_bar(data=test, aes(y = value, x = year, fill = cat), stat="identity",position='dodge') + theme_bw() 

test and I need to split each "cat" into "cond" (true or false). How to do it?

+13
source share
1 answer

You can put cat on the x axis and use facet_grid with year :

 ggplot() + geom_bar(data=test, aes(y = value, x = cat, fill = cond), stat="identity", position='stack') + theme_bw() + facet_grid( ~ year) 

enter image description here

+18
source

Source: https://habr.com/ru/post/1501945/


All Articles