2
library(ggplot2)
p <- ggplot(mpg, aes(displ, hwy)) + geom_point()

# Use vars() to supply faceting variables:
p + facet_wrap(vars(class))

Sample code above makes a facet grid. How can it be possible to specify which variables are in each rows, for example if I want:

"2seater" and "compact" in row 1--

"midsize" and "minivan" and "pickup" and "subcompact" in row 2--

and "suv" in row 3.

Lastly, can it be possible to add a word the left hand side before each row of plots that describes the series of plots, for example "ROW A" for row 1--"ROW B" for row 2-- "ROW C" for row 3.

Desired/sample output shown below

enter image description here

Maurits Evers
  • 49,617
  • 4
  • 47
  • 68
bvowe
  • 3,004
  • 3
  • 16
  • 33
  • 5
    This won't be possible using `facet_wrap`/`facet_grid` without a good amount of tweaking of the resulting plot `grobs`. I remember answering [a related question](https://stackoverflow.com/questions/49521848/remove-unused-facet-combinations-in-2-way-facet-grid) a while back, perhaps it's worth taking a look. Alternatively, you may want to consider arranging multiple `ggplot`s using `cowplot::plot_grid`, `ggpubr::ggarrange` or `gridExtra::grid.arrange`. – Maurits Evers Oct 16 '19 at 01:02
  • 1
    Related https://stackoverflow.com/a/30372692/786542 & https://stackoverflow.com/a/49305765/786542 – Tung Oct 16 '19 at 04:25

0 Answers0