21

次のグラフがあります

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()

テスト そして、各「cat」を「cond」(trueまたはfalse)で割る必要があります。それ、どうやったら出来るの?

4

1 に答える 1

28

catx軸に配置して、次のコマンドで使用facet_gridできyearます。

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

ここに画像の説明を入力してください

于 2012-11-23T13:20:22.920 に答える