I would like to put the facet labels on the left side all the way to the left so that the y-axis title is to the right of it. I can already create a suitable spacing, but I can't swap the order.
library(ggplot2)
library(tibble)
tg <- ToothGrowth %>%
as_tibble()
tg %>%
ggplot(aes(supp, len)) +
geom_boxplot(aes(fill = supp)) +
theme(strip.placement = "outside",
strip.switch.pad.grid = unit(1, "cm")) +
facet_grid(dose ~ ., switch = "y")
This order is important because I am putting this figure together with two others to have a more consistent layout. Thanks!!
EDIT: The best solution for me was the second link in aosmith's comment.
Here is the code:
tg %>%
ggplot(aes(supp, len)) +
geom_boxplot(aes(fill = supp)) +
facet_grid(dose ~ ., switch = "y") +
theme(strip.placement = "outside",
strip.switch.pad.grid = unit(1, "cm"),
axis.title.y = element_text(vjust = -15))
The solution with the grid package also looks good, but it is complicated to continue working with it. The solution with the fake axis changes the spacing of the x-axis tick marks and "label = " does not accept expressions. Thanks to all for the great help!



