Changing colour of some coefficients in stanplot/bayesplot

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

myPlot=stanplot(myFit,pars=c("p1","p2","p3"),prob=0.95,prob_outer=0.95)+
scale_y_discrete(labels=c("label1","label2","label3"))

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
Jacquie

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 %>% 
  as.data.frame() %>% 
  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…

In case this might be useful for others: Martin’s suggest above works well. There is also a beautiful package (@strengejacke) that does it and that I didn’t see before: https://strengejacke.wordpress.com/2017/10/23/one-function-to-rule-them-all-visualization-of-regression-models-in-rstats-w-sjplot/