Reputation: 366
Suppose I have this dataframe:
x <- seq(-10, 9.9, by = .1)
y <- seq(0, 19.9, by = .1)
z <- rep(c(1,2,3,4),each=50)
df <- data.frame(col_x = x,
col_y = y,
col_z = z)
and I plot it as such:
ggplot(df, aes(x = col_x, y = col_y))+
geom_point()+
facet_wrap(~col_z, strip.position = "left", nrow = 4)+
theme(axis.title.y = element_blank(),
strip.text.y.left = element_text(angle=0))
However, in this plot, the facet labels are after the y axis. How do I make it so that the facet labels come before the y axis. In other words, they are further left?
Thanks in advance!
Upvotes: 2
Views: 855
Reputation: 16998
You could try this:
library(ggplot2)
ggplot(df, aes(x = col_x, y = col_y))+
geom_point() +
facet_wrap(~col_z, strip.position = "left", nrow = 4) +
theme(axis.title.y = element_blank(),
strip.text.y.left = element_text(angle=0),
strip.placement = "outside")
The strip.placement = "outside"
argument moves the facet labels next to the ticks (which I think is the better placement). So your plot looks like
Upvotes: 3