79724457

Date: 2025-08-04 03:34:07
Score: 4
Natty:
Report link

I like the patchwork package suggestion that was given in this post. So far I have come up with this solution to handle a variable number of graphs, but I can't figure out how to make it handle numbers not divisible by 3. Any suggestions? Can we make it simpler?

    x <- c(5,7,2,4,9)
    y <- c(2,10,15,8,14)
    df <- data.frame(x,y)
    myfunct <- function(i){
      p<-ggplot(df, aes(x=x,y=y*i)) + geom_point()
      return(p)
    }
    myGrobs <- lapply(1:10,myfunct)
    library(patchwork)
    pdf("test pdf.pdf", width = 6.5, height = 9, paper="letter")
    for(i in c(1,4,7)){
      print(myGrobs[[i]] / myGrobs[[i+1]] / myGrobs[[i+2]])
    }
    dev.off()
Reasons:
  • RegEx Blacklisted phrase (2): Any suggestions?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: BenW