使用facet_wrap在ggplot2中安排列和子列?

时间:2018-03-18 03:44:10

标签: r ggplot2 facet-wrap facet-grid

我想知道如何对以下ggplot(在油漆中编辑)绘制的图表进行分组:Plot

看起来facet_wrap()facet_grid()函数不能用于排列列和子列。

我可以使用任何R包吗?

由于

1 个答案:

答案 0 :(得分:0)

您可以将用于列和子列的因子相乘。

library(ggplot2)

ggplot(mtcars, aes(disp, mpg)) + 
  geom_point() + 
  facet_wrap(~ cyl * gear, labeller = label_both)

enter image description here

这里的labeller label_both也很有用,因为它会在facet标题中的值之前添加变量名称。