0
積み重ねたIDバープロットを作成しようとしていますが、ggplot2
はデータをまとめて保持しています。ggplot2スタックバープロットのトラブルシューティング
セクタごとにそれぞれのカテゴリごとに積み上げプロットを提供する代わりに、direct
,indirect.down
およびindirect.up
のカテゴリをまとめて集計します。
test.df = data.frame(scenario=(c("s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3",
"s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3",
"s1", "s1", "s1", "s2", "s2", "s2", "s3", "s3", "s3")),
sector=(c("Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services",
"Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services",
"Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services", "Agriculture", "Manufacturing", "Services")),
loss=(runif(27,0,1000)), shock=(c("direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down",
"direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down",
"direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down","direct", "indirect.up", "indirect.down")))
library(ggplot2)
ggplot(test.df, aes(x=sector, y=loss)) + geom_bar(stat = "identity", aes(fill=shock)) + facet_wrap(~ scenario) + coord_flip()
私はそれが各セクタへの衝撃が積層されているかという点で、このようになりたい:
を感謝Sumedh、私は今、整流されています問題。 –