-1

In How to change the order of facet labels in ggplot (custom facet wrap labels) it is described how to add group levels for later use in a sorted facet grid.

How can I generate group levels to mtcars that will turn the number of cylinders in the reversed order?

Community
  • 1
  • 1
Jonas Stein
  • 6,363
  • 7
  • 39
  • 70

1 Answers1

2

The trick here is to sort the unique values, and then set the levels as the reverse.

for example.

mtcars <- within(mtcars, Group <- factor(cyl, levels = rev(sort(unique(cyl)))))


ggplot(mtcars) + geom_point() + facet_grid(~Group)
mnel
  • 110,110
  • 27
  • 254
  • 248