Change aesthetics conditional_effects

Please also provide the following information in addition to your question:

  • Operating System: Windows 10
  • brms Version: 2.11.1

Dear all,

I am new to brms, and really like the package! However, I am running into trouble when plotting some results.

I ran a model using the sratio family and a continuous predictor. I am trying to plot the results using conditional_effects, but I want to change the default aesthetics. However, I have been trying many things, based on my experience with ggplot, but I cannot change it. For example, I have tried to use line_args to change the linetype, but it keeps giving me errors and warnings.

My goal is to change the different colours to different linetypes (all black), and to give the categories in the legend a name. Does anybody have any idea how to do this?

Thanks in advance!

Reproducible example:

mtcars$carb<- as.ordered(mtcars$carb)
example<-brm(carb~hp, data=mtcars, family=sratio)
plot(conditional_effects(example, categorical=T))

Resulting plot:


For starters I’d recommend reading through the ?conditional_effects help very carefully. Every time I revisit it I find some new tidbit that helps me plot my model output.

In your case, I would try something like this:

#creating conditional effects object
c_eff <- conditional_effects(example, categorical = T))

#creating plot
ugly_plot <- plot(c_eff, plot = FALSE)[[1]] + 

#at this point you have a ggplot object to work with
#put whatever fill & colors you want here, or anything else!
scale_fill_manual(values = c("1"= "green", 
                             "2"= "#7570b3", 
                             "3"= "#1b9e77",
                             "4" = "grey20",
                             "5" = "blue",
                             "6" = "grey80")) +
scale_color_manual(values = c("1"= "black", 
                      "2"= "black", 
                      "3"= "orange",
                      "4" = "grey20",
                      "5" = "blue",
                       "6" = "grey80")) +


and also take a look at Geom_point in marginal_effects where I was helped with a similar issue. The inherit.aes = FALSE can be critical for some plotting features.


Thanks Jon!

I still had some trouble with implementing the linetype though, but since I now understand the datastructure of the conditional_effect object a bit better, it was not so difficult to extract the data and create a new dataframe to use in ggplot2 altogether.

Hi everyone. I still have trouble to change the geom_point aesthetic in conditional_effects. My aim is to change the shape of the observed values. How can I do this modification ?

Dear Leo,

Sorry for the late reply. Hope you have figured it out already.

I extracted the data from the conditional_effects object, and then plotted it myself using ggplot2. This makes it a lot easier to change the aesthetics. You can obtain the dataframe for the plot by using:
conditional_effects(“model name”)[[number of plot you need]]

Good luck!

A slightly more explicit way is to use the $ operator to identify the term for which you wish to extract data. Saves your having to figure out which plot number is associated with which term.

data_term <- conditional_effects(model)$term

Note that to plot interactions, which take the form term1:term2, it is necessary to enclose the expression in tick marks to avoid problems arising from the : character:

data_term <- conditional_effects(model)$`term1:term2`
1 Like