How to save brms pp_check() plot with ggsave()?

I am struggling to save brm pp_check() plot exactly as it is with ggsave(). Could you please help?

Reproducible example

df = tibble(
  y = rnorm(100, 10, 5),
  x = rnorm(100, 20, 20))

fit = brm(y ~ x, data = df, iter = 500)

fit %>% pp_check()

How can I save the plot exactly as it is with ggsave() function?

Doesn’t it work just to put ggsave(filename) as a separate command afterwards? Seems to work for me.

df = tibble(
  y = rnorm(100, 10, 5),
  x = rnorm(100, 20, 20))

fit = brm(y ~ x, data = df, iter = 500, backend="cmdstanr")

fit %>% model.check() %>% plot()

brm_model1 %>% pp_check()
ggsave("test.png")
1 Like