# Problems passing "conditional\_effects" to ggplot2

**URL:** https://discourse.mc-stan.org/t/problems-passing-conditional-effects-to-ggplot2/23423
**Category:** brms
**Created:** [July 12, 2021, 7:43pm UTC](https://discourse.mc-stan.org/t/problems-passing-conditional-effects-to-ggplot2/23423 "2021-07-12T19:43:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Sophia\_H](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/sophia_h/32/12205_2.png) [@Sophia\_H](https://discourse.mc-stan.org/u/Sophia_H)
#### Post date: [July 12, 2021, 7:43pm UTC](https://discourse.mc-stan.org/t/problems-passing-conditional-effects-to-ggplot2/23423/1 "2021-07-12T19:43:53Z")

</div>

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?

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/mc_stan/original/2X/c/c5673f7b3e3d83ce1c44a1bf1b6adccf0c97880f.png)

```
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

---

<div class="post-metadata">

### Author: ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)
#### Post date: [July 28, 2021, 1:25pm UTC](https://discourse.mc-stan.org/t/problems-passing-conditional-effects-to-ggplot2/23423/2 "2021-07-28T13:25:18Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Peter\_Clayson](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/peter_clayson/32/251_2.png) [@Peter\_Clayson](https://discourse.mc-stan.org/u/Peter_Clayson)
#### Post date: [July 28, 2021, 5:38pm UTC](https://discourse.mc-stan.org/t/problems-passing-conditional-effects-to-ggplot2/23423/3 "2021-07-28T17:38:35Z")

</div>

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!
