I wrote a R code to display multiple images in one:
library(tidyverse)
library(fable)
myfit <- tsibbledata::global_economy |>
filter(Code %in% c("CAF", "AUT")) %>%
model(arima = ARIMA(Exports))
plot_list <- sapply(1:2, function(x) {myfit %>% slice(x) %>%
feasts::gg_tsresiduals() +
labs(title=x)})
gridExtra::grid.arrange(grobs = plot_list,
layout_matrix = rbind(c(1,1), c(2,3), c(4,4), c(5,6)))
But it generates 2 blank plots first at the sapply level inside the RStudio notebook.
I tried to add the invisible function, but that did not solve the problem:
[...]
plot_list <- sapply(1:2, function(x) {invisible(myfit %>% slice(x) %>%
feasts::gg_tsresiduals() +
labs(title=x))})
[...]
I also tried to add chunk options such as results='hide' or fig.keep='last'. The last chunk option works into the html ouput (Knit), not inside the RStudio notebook output, with the code above but that does not suit me because I will need to print several plots like this, not only the last.
How can I get rid of it?