0

I am trying to print a few groups of 3 plots each in R. In every grouping, 1 plot is a ggplot, and the other 2 are base R plots. The ggplot is successfully plotting each item in the list, but the base R plots are displaying the last item in the list for every output. This is my code

for (i in 1:length(drop_data)){
    fit_data(drop_data[i])
    print(i)
    lay <- rbind(c(1,2),
                 c(1,3))
    
    resid <- ~plot(residuals[[i]]) + abline(0,0)
    qplot <- ~qqnorm(residuals[[i]])
    
    gs <- list(plots[[i]], as_grob(resid), as_grob(qplot))
    str(gs)
    grid.arrange(grobs = gs, layout_matrix = lay)}

plots is a list of ggplots, and resid and qplot are both lists of base R plots.

DWM024
  • 31
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Explicitly list any non-base R packages you are using. – MrFlick Sep 11 '20 at 22:16
  • Do you have to explicitly `print` grid objects like you do `ggplot2` objects? How did you store/create `plots`? (Are they from `recordPlot` or something else?) – r2evans Sep 11 '20 at 22:24
  • This seems relevant : https://stackoverflow.com/a/63366579/13513328 – Waldi Sep 11 '20 at 22:51

0 Answers0