使用ggplot2在类/组中嵌套构面

时间:2015-05-13 09:09:31

标签: r ggplot2

我想在一个约30个项目的方面代表值(在这种情况下为条形),这些项目属于五个可变大小的超级组。小组之间的对比很有趣,所以我想把每个小组都展示成一个小条。到目前为止:

example <- data.frame(class=rep(c("I", "I", "I", "II", "II"), 2),
                      unit=rep(letters[1:5], 2),
                      variable=rep(c("var1", "var2"), 5),
                      value=rnorm(10))
ggplot(example, aes(x=unit, y=value, fill=variable)) +
    geom_bar(stat="identity", position="dodge") +
    facet_wrap(~class, scales="free_x", ncol=1)

这产生了这样的东西: enter image description here

问题在于,使用“free_x”刻度,每个刻面中条形的宽度根据该组中的项目数而变化。没有“free_x”,所有项目都会显示在所有方面。

问题类似于: Nested facet plot with ggplot2

0 个答案:

没有答案