Order nested facet labels in facet_grid

So, I'm trying to create a grid of graphs bordering three different variables. I can create a story grid just fine, the only thing I have is that the order in which the labels are placed does not look out of order. Here is a simple example of what I'm doing:

library(ggplot2)
data(mtcars)
qplot(mpg, wt, data=mtcars) + facet_grid(cyl +am ~ vs, labeller = label_both)

which creates the following graph:

enter image description here

Now, for the most part, the graph looks great, but for the shortcuts on the right side we see that cyl is marked as β€œfirst” (ie close to the plot) and am nested outside, but the way to plot the graph is that the edges are displayed with am nested in cyl .

, , am cyl, . , " facet_grid" " ggplot2", , , , . , , , , , .

!

+4
1

, , , , ggplot . , , , , , , :

qplot(mpg, wt, data=mtcars) +
    facet_grid(am + cyl ~ vs, labeller = label_both)

enter image description here

, , alistaire. label_both() :

label_rev <- function(labels, multi_line = TRUE, sep = ": ") {
  label_both(rev(labels), multi_line = multi_line, sep = sep)
}

:

qplot(mpg, wt, data=mtcars) +
    facet_grid(cyl + am ~ vs, labeller = label_rev)

enter image description here

+2

All Articles