Rstan::traceplot without permanently(?) altering display format

Hi all. Relatively new to Stan and R, so hopefully this is something simple for me to fix. Running in Rstudio, I generate a model fit using the ulam() function in the rethinking package, then run rstan::traceplot to generate plots, and then any further plots I generate use the formatting that came with the running of rstan::traceplot. For example, model m5.4 is an ulam, and I call rstan::traceplot directly as follows:

rstan::traceplot(m5.4, n_cols=1)
plot(x_spur ~ x_real)

When I go to plot(x_spur ~ x_real) afterwords, the plot is squished into a vertically-small plot, which was what one of the sections (parameters) of the traceplot had as a format. The only way I know how to reset the formatting is to click the “Clear all plots” button in Rstudio.
a) Is rstan::traceplot() somehow “capturing” the Plots section of Rstudio and not releasing it after it’s done?
b) If so, how do I get the function to no longer dictate the layout of my next plots? That is, I only want rstan::traceplot to temporarily force 1-column formatting, then no longer force it after it’s done generating the plot.

I’m assuming that by calling traceplot directly using rstan:: that I’m not introducing anything from the rethinking package that I used to generate model m5.4. Is this how things work in R?

Thank you.

This looks like an issue with the traceplot method for the ulam objects. It changes the graphics mode to “Multi Frame” to put multiple plots on the same page, but does not switch back afterwards (like it should).

This is something that should really be addressed in the rethinking package, but in the mean time you can manually set it back without resetting everything by issuing the following command after running traceplot:


This sets the graphics state so the next plot will use the entire device and not make room for multiple plots.

1 Like


If you are in RStudio you simply click “Clear all plots”, I believe.

1 Like

Great, that worked, thank you.

Yep, that does work, along with the par(mfrow=c(1,1)) command that glsnow provided. Thanks.