How do I move ggplot strip labels so that there is one on top and one on the right and only label colums and rows instead of every plot
The ggh4x::facet_grid2()
function allows for independent scales within columns or rows in a grid layout. Disclaimer: I'm the author of ggh4x.
library(tidyverse)
dat <- tibble(River = c(rep(letters[1:6],27))) %>%
mutate(cohort=rep(seq(2007,2015,1),18),
mu = c(rnorm(54,300,25),
rnorm(54,0.5,0.15),
rnorm(54,-0.75,0.1)),
param = c(rep('var1',54),
rep('var2',54),
rep('var3',54))) %>%
group_by(param) %>% mutate(
upr = mu+2*sd(mu),
lwr = mu-2*sd(mu))
p1 <- ggplot(data = dat) +
geom_point(aes(x=cohort, y=mu)) +
geom_errorbar(aes(x=cohort, ymin=lwr, ymax=upr),
width=0)
p1 +
ggh4x::facet_grid2(factor(River) ~ param,
scales = 'free', independent = "y")
Created on 2022-01-13 by the reprex package (v2.0.1)