ggplot: missing error bars and grouping lines in 3 way interaction plot

Viewed 60

I am trying to plot the information contained in one dataframe X. However, I am not managing to include the error bars, nor the connection lines between the same coloured dots. For now, the code to obtain the plot attached is as follows:

 ggplot(dataframeX, aes(x= points, y=emmean, colour= Gamers)) + 
  geom_pointrange(aes(ymin=emmean-SE, ymax=emmean+SE)) +
  facet_grid(. ~ Team) +
  theme_light()

It did not working adding:

geom_line(aes(color=Gamers))+
geom_point(aes(ymin=emmean-SE, ymax=emmean+SE), lwd = 2.5) 

Any idea on how should I proceed?

1 Answers

As @MrFlick showed, the group aesthetic is important to set. You can also just use geom_point rather than including both geom_errorbar and geom_pointrange.

library(tidyverse)

ggplot(dataframeX, aes(x = Valence, y = emmean, colour = Opponent)) +
  geom_point(aes(x = Valence, y = emmean), lwd = 2.5) +
  geom_errorbar(aes(ymin = emmean - SE, ymax = emmean + SE)) +
  geom_line(aes(color = Opponent, group = Opponent)) +
  facet_grid(. ~ Drug) +
  theme_light()

Output

enter image description here

Related