我有以下图表
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()
Run Code Online (Sandbox Code Playgroud)
我需要将每个'猫'除以'cond'(真或假).我怎么做?
Sve*_*ein 21
你可以把cat
在x轴和使用facet_grid
与year
:
ggplot() +
geom_bar(data=test, aes(y = value, x = cat, fill = cond), stat="identity",
position='stack') +
theme_bw() +
facet_grid( ~ year)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13233 次 |
最近记录: |