0
ggplot(data = df) + 
aes(x= Name, y=L7, fill=ID) +
 geom_col(position= position_dodge()) + 
facet_wrap (~Peptide, scales= "free") +
xlab("Compound") + 
ylab("CV(%)") +
theme_classic() +
theme(axis.text.x = element_text( angle= 90, hjust= 1, vjust= 
1),
    strip.text.y= element_text(angle = 0, hjust= 1)) +
geom_hline(yintercept = 5, color= "green") +
geom_hline(yintercept = 10, color = "orange") +
geom_hline(yintercept = 15, color = "red") +
theme(panel.spacing.x = unit(1, "cm")) +
labs(title = "L7", subtitle= "RR", y= "CV(%)")

ggsave(here("output","IFCC_exp02.03_L7_final.png"))

`Today I tried 100 options supplied by chatGPT to add a y-axis title to every plot in facet_wrap. It is all the same unit (CV%), only different compound groups (hence the facets). Why is this so complicated? It seems impossible to do and other options than facet_wrap seem so overcomplicated. Is there a way to add a y-axis title to every plot in facet_wrap?? Much appreciated, because I have given up all hope on this topic..

Peace Jules

Quinten
  • 35,235
  • 5
  • 20
  • 53
  • The short answer: Yes, this is not possible by design. The overarching idea of small multiples (facets) is to show the same variables across their x and y. – tjebo Mar 01 '23 at 17:02
  • related thread: https://stackoverflow.com/questions/70022117/how-to-add-y-axis-title-for-each-facet-row-in-ggplot – tjebo Mar 01 '23 at 17:05

1 Answers1

1

You could use patchwork to plot multiple plots separately side by side like this:

library(patchwork)
library(ggplot2)
library(dplyr)

p1 <- mtcars %>%
  ggplot(aes(disp, hp)) + 
  geom_point() 
p2 <- mtcars %>%
  ggplot(aes(disp, hp)) + 
  geom_point() 
p3 <- mtcars %>%
  ggplot(aes(disp, hp)) + 
  geom_point() 

p1+p2+p3

Created on 2023-03-01 with reprex v2.0.2

Quinten
  • 35,235
  • 5
  • 20
  • 53