3

I'll start with a simple faceted histogram using mtcars, faceting on the variables vs and am.

library(ggplot2)
data(mtcars)
ggplot(mtcars, aes(wt)) + 
    geom_histogram() + 
    facet_grid(vs ~ am)

I want to have the x-axis label underneath each facet so switch to facet_wrap.

ggplot(mtcars, aes(wt)) + 
    geom_histogram() + 
    facet_wrap(vs ~ am, nrow = 2, scales = "free")

Now the strips for vs and am are stacked. How can I make the strips for am go across the top and the strips for vs appear on the right side as is the case in the first histogram using facet_grid?

pogibas
  • 27,303
  • 19
  • 84
  • 117
Herb Wilson
  • 85
  • 1
  • 5

0 Answers0