I am using rstan to estimate a model. After the sampler runs, I use plot() to produce a plot of point estimates and uncertainty intervals for the estimated parameters. However, it uses the “ugly” names for the parameters (e.g. sigma_individual), and I would like to report “pretty” names (e.g. Individual-level SD) on the axis labels.

I have figured out I can use scale_y_continuous(breaks=1:2, labels=c(“a”,“b”), but it seems to change the order of things, which makes it hard to know exactly what I’m doing.

I posted this on stackoverflow before realizing there’s a stan specific forum, apologizes for cross-posting.

This should be easier if you use bayesplot::mcmc_intervals(). The plot method for stanfit objects is still using the older version of the function at the moment. So something like this:

library(bayesplot)
library(ggplot2)
x <- as.matrix(stanfit, pars = ...)
mcmc_intervals(x) + scale_y_discrete(labels = my_labels) # my_labels is character vector

Alternatively you can change the column names of x and that should do the trick too.

You can use named vectors as labels in ggplot2, which automatically correctly assigns the labels to the axis ticks, no matter which order you have. However, this does not work for continuous scales: