我有下面的图表
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()
and I need to divide each 'cat' by 'cond'(true or false). How do I do that?
你可以把cat
在 x 轴上并使用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)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)