Search code examples
rggplot2facet-grid

Change order margin is presented in facet_grid ggplot2?


I've seen several answers on how to change the order of facets by reordering the factor levels. But I would like to change the order in which the margin is presented. So basically have (all) displayed on the left panel before 4, 6, 8. Thanks in advance!

library(ggplot2)
qplot(mpg, wt, data=mtcars) + facet_grid(. ~ cyl, margins=TRUE)

enter image description here


Solution

  • How about

    mtcars2 <- rbind(mtcars, within(mtcars, cyl <- "(All)"))
    
    qplot(mpg, wt, data = mtcars2) + facet_grid(. ~ cyl)
    

    enter image description here