Controlling axis labels in stan plots

Greetings all,

Here is a chunk of code that I am using to create stan plots for a document I am writing.

library(egg)
library(gridExtra)
stanplot <- stan_plot(myfit, pars=c(“alpha”,“beta1”,“sigma”))
stantrace <- stan_trace(myfit,inc_warmup=T, pars=c(“alpha”,“beta1”,“sigma”))
standens <- stan_dens(myfit, pars=c(“alpha”,“beta1”,“sigma”))
stanac <- stan_ac(myfit, pars=c(“alpha”,“beta1”,“sigma”))
stanac <- stanac + legend_none()
ggarrange(plots=list(stantrace,standens,stanac),nrow=3,
widths = list(unit(5,‘in’), unit(5, ‘in’)),labels=c(‘a’,‘b’,‘c’))
@

Everything is working fine. I have two questions First, for the AC plot, I am getting a label for the y-axes that says Avg. Autocorrelation. Is it possible to remove that label? Second, for the trace plots is there a way to scale the y-axis for specific parameters? For example, the plot for sigma shows a very thin trace line because the range of values are so small. I would like to magnify that plot somehow but also stay within the boundaries of the entire plot, so rescaling the y-axis would be the way to go, I think.

Thanks in advance,

David

You should be able to replace the y-axis label by doing:

stanac <- stan_ac(myfit, pars=c(“alpha”,“beta1”,“sigma”))
stanac <- stan_ac + ylab('my new label')

And for setting the scales to be fit to each facet, I think you can do:

stanac <- stanac + facet_wrap(~parameter,scales='free')

Hi Mike,

Thanks for the advice. It was very helpful. I think I am still having some trouble with the facet_wrap. I have two figures (and the code) attached. The first is without facet_wrap, and you’ll see that things look mostly fine. My problem is the scale of alpha and sigma in the trace plot, which show up as very thin lines. The second figure shows what happens when I add the facet_wrap in the way that I thought you might be suggesting (I’m focusing on sigma here, but alpha is a problem too). You’ll see that the whole plot is off and nothing changed for the scale. Advice appreciated. Thank you - DavidFig1.pdf (153.4 KB) Fig2.pdf (153.6 KB)

Oh! Now that I see your figures, the issue is that the first few samples have huge variability, forcing a wide y-axis. Do these plots include warmup samples? If not, that kind of post-warmup behaviour strongly suggests that more warmup is necessary.

That was it. Thanks!