How to add geom_line() correctly with conditional_effects() in brms?

Hi everybody,

I want to use geom_line to link the points on the picture got from conditional_effects() of brms package.
The daulft picture got from conditional_effects look like this:

p<-conditional_effects(model, "hour2:period")

If I use add the following codes, it will draw two lines but will not link the points correctly, see the following picture:

plot(p)[[1]] + 
  geom_line(aes(group = period))

Does anyone have any expriences to solve this issue? Many Thanks!

The points and whiskers are “dodged” (shifted to either side of the 0 and 1 points on the x-axis), so you need to dodge the lines as well:

geom_line(aes(group = period, position=position_dodge(0.2))

I’m not sure of the actual dodge value that the conditional_effects plot is using, so you might need to try a few values to see what works.

1 Like

Many thanks! It works:

plot(p)[[1]] + 
  geom_line(aes(group = period),position=position_dodge(0.4))