0

I want to move A, B, C, D labels so that they are akin sub "x-strips". Basically move them leftward, to the top of the plots hanging above the corresponding X and Y plots. Any suggestions on how to do this?

set.seed(14)
df <- data.frame(
  var.test = rep(c("X","Y"),each =  40),
  var.test2 = rep(c("A","B","C","D"), times = 20),
  val.test = rnorm(80,4,5),
  x = c(1:80)
)

my.formula <- c(y~x,y~x,y~x,y~x,y~x + I(x^2), y~x + I(x^2),y~x + I(x^2), y ~x)

ggplot(df, aes(x = x, y = val.test)) + 
  geom_point() + 
  facet_grid(var.test2~var.test)+ theme(strip.text.y = element_text(angle = 360))

enter image description here

Rspacer
  • 2,369
  • 1
  • 14
  • 40
  • Perhaps you can illustrate what you are trying to achieve, it's not clear to me. But generally, options for strip placement are quite limited. – Axeman Apr 23 '22 at 18:45
  • What you need is exactly in this post: https://stackoverflow.com/questions/52706599/how-to-position-strip-labels-in-facet-wrap-like-in-facet-grid – Daniel Apr 23 '22 at 18:57

1 Answers1

0

Do you mean like this by any chance ... ?

library(tidyverse)

set.seed(14)
df <- data.frame(
  var.test = rep(c("X","Y"),each =  40),
  var.test2 = rep(c("A","B","C","D"), times = 20),
  val.test = rnorm(80,4,5),
  x = c(1:80)
)

my.formula <- c(y~x,y~x,y~x,y~x,y~x + I(x^2), y~x + I(x^2),y~x + I(x^2), y ~x)

ggplot(df, aes(x, val.test)) + 
  geom_point() + 
  facet_wrap(~ var.test + var.test2)+ 
  theme(strip.text.y = element_text(angle = 360))

Created on 2022-04-23 by the reprex package (v2.0.1)

Carl
  • 4,232
  • 2
  • 12
  • 24