Imagine for a moment that there is some good reason to have a variable like mpg on different scales for each row in a faceted ggplot.
How can I put the y-axis label inside the facet strip labels, so that it is very clear that the units are described by the y-axis label but not the facet? Suggestions that modify the code below especially welcomed.
As you're imagining this scenario, please also imagine there is a good reason not to have the strips on the right, and not to have the double strip e.g. that would occur with facet_wrap
, and help me get "miles per gallon" between "mini", "modest", and "muscle" and the y-axis ticks :-) thanks!
library(tidyverse)
data(mtcars)
mtcars %>%
mutate(transmission=c("real", "robot")[am+1]
, engine=c("mini", "modest", "muscle")[cyl/2-1]) %>%
ggplot(aes(wt*1000, mpg)) +
geom_point() +
facet_grid(engine ~ transmission, switch = "y", scales = "free") +
labs(x="vehicle weight (lbs)", y = "miles per gallon" ) +
theme_classic() +
theme( panel.spacing=unit(2, "lines")
, strip.placement.y = "outside"
, strip.background = element_blank()
, strip.text = element_text(face = "bold")
)