Search code examples
rggplot2stanrstan

How to adjust parameter labels in plot.stanfit()?


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.


Solution

  • You only need a slight adjustment of this question: Customize axis labels

    We can use a named vector instead of supplying breaks and labels separately. Then it should be clearer what is going on.

    library(ggplot2)
    df <- data.frame(x = 1:5, y = sample(1:10, 5, TRUE))
    
    qplot(factor(x),y, data = df) + 
      scale_x_discrete(labels=c("1" = "foo", "2" = "bar", "3" = "baz",
                                "4" = "phi", "5" = "fun")) +
      xlab(NULL)
    

    For your case, that would be something like:

    scale_y_continuous(labels = c("sigma_individual" = "Individual-level SD", etc.)