Changing colour of some coefficients in stanplot/bayesplot

Hi there,
I have plotted my brms results like this:


Is it possible to change the colour of just the first bar? I’ve tried

+ scale_color_bayesplot(values=c("red","black","black"))

but that does nothing

I’d be very grateful for any advice

Unfortunately, the color aesthetic is not bound to anything in stanplot or the underlying mcmc_intervals call, so you cannot do it directly. The quickest way to do it manually is probably using the summary function (below a quick hack in tidyverse style for fixed parameters only):

summary(fit)$fixed %>% %>% 
  rownames_to_column("parameter") %>% 
  ggplot(aes(color = parameter, y = parameter)) + 
    geom_segment(aes(x = `l-95% CI`, xend = `u-95% CI`, yend = parameter)) + 
    geom_point(aes(x = Estimate) )

If you need both 50% and 95% intervals you either need to cleverly combine two summary calls or directly use and process the result of posterior_samples(). posterior_samples() would also allow you to easily work with all parameters at once (without referencing throuhg $fixed or $random) and access the actual random effects ($random only gives you the sd parameters).

Hope that helps.

thank you so much, that’s very helpful! I was not quite sure where I could find out how it works and whether I’m just missing something as I’m still getting used to R…