Problems passing "conditional_effects" to ggplot2

Hello!

I want to plot the interaction between two of my variables. When I plot it using “plot(conditional_effects(m4, effect = “Ach:gender”), point = TRUE)” I get the plot I want, however I cant change the labels of the conditions and the axes. So I tried passing it on to ggplot (as shown in the code below), where the axes labels will change the way I want them to, but the legend (gender) will not change. Instead there is another legend created and I have two legends. Is there any way to fix that problem, and if the solution is via ggplot, is there a way to include the points?

plot.ach <- conditional_effects(m4, effects = "Ach:gender")

plot(plot.ach, plot = FALSE) [[1]]+
  labs(x = "Achievement", y = "Dominance",  = "Gender")
  • Operating System: Windows 10
  • brms Version: 2.15.0

Thanks already!
Sophia

1 Like

Hi,
sorry for not getting to you earlier. It appears that providing your own definition of the conditions (see make_conditions) and then rewriting the labels in the cond__ column. Alternatively, you might just rename the variables/factor levels in the data and refit the models.

Best of luck with your modelling!

Try editing scale_color_discrete and scale_fill_discrete.

Something like…

legend_name <- "Gender"
legend_limits <- c("Female","Male")
legend_labels <- c("Female","Male")

plot(plot.ach, plot = FALSE) [[1]] +
  labs(x = "Achievement", y = "Dominance") +
  scale_color_discrete(name = legend_name,
                       limits = legend_limits,
                       labels = legend_labels) +
  scale_fill_discrete(name = legend_name,
                      limits = legend_limits,
                      labels = legend_labels)

This should do the trick. You might not need both limits and labels manually defined, but without the code I can’t check for myself. Good luck!