Home > other >  How to move one, but not both, set of labels in facet_wrap in ggplot?
How to move one, but not both, set of labels in facet_wrap in ggplot?

Time:10-08

Consider the two following examples:

ggplot(mtcars, aes(x = wt, y = qsec))  
  geom_point()  
  facet_grid(cols = vars(vs), rows = vars(gear), scales = "free")  
  geom_vline(aes(xintercept = mean(wt)))

enter image description here

Notice how this produces the same values of xintercept for geom_vline in the same column, even with scales = "free" as was explained in enter image description here

We now get the xintercepts displayed separately in each facets. However, now the labels of both faceting variables are above the graphs. How do I move them so that, like in the facet_grid, one variable's labels are on top and one on the right? I tried using strip.position = c("top", "right") in facet_wrap, but that gives the following error:

Error in match.arg(strip.position, c("top", "bottom", "left", "right")) : 
  'arg' must be of length 1

So then how to do it?

CodePudding user response:

Adapted from enter image description here

  • Related