问题描述
我已经看到了几个有关如何通过重新排序因子级别来改变构面顺序的答案。但是我想更改保证金的显示顺序。因此,基本上(all)
在4
,6
,8
之前显示在左侧面板上。预先感谢!
library(ggplot2)
qplot(mpg,wt,data=mtcars) + facet_grid(. ~ cyl,margins=TRUE)
解决方法
怎么样
mtcars2 <- rbind(mtcars,within(mtcars,cyl <- "(All)"))
qplot(mpg,wt,data = mtcars2) + facet_grid(. ~ cyl)
,
我有一个非常复杂的解决方案,您总是可以编辑grobs结构:
library(ggplot2)
gg = qplot(mpg,data=mtcars) + facet_grid(. ~ cyl,margins=TRUE)
ggg = ggplotGrob(gg)
ggg$grobs = ggg$grobs[c(1,5,2:4,9,6:8,10:15,19,16:18,20:27)]
grid::grid.newpage()
grid::grid.draw(ggg)