Hello! I am trying to create a line graph with SE using data that has within subject variables. I converted my data into long format using the rstatix package:
Then I summarized the data using the summarySEwithin function in the Rmsic package:
PrefSE <- summarySEwithin(PrefAll, measurevar = "Intake", withinvars = "Day", idvar = "...1", na.rm = TRUE, conf.interval = 0.95)
which gave me:
Then I want to graph it in a line graph across days, while separating it into treatments (PCB) -- so I want to have one line for treatment A and one line for treatment B, across Days 2 - 11. However my code:
ggplot(PrefSE, aes(x = Day, y = Intake, group = PCB_Treatment, color = PCB_Treatment)) +
geom_line() +
geom_errorbar(width = 0.1, aes(ymin = Intake-se, ymax = Intake+se)) +
geom_point(shape=20, size=2, fill=c("black")) +
ylim(25,100)
gave me:
Error: Aesthetics must be either length 1 or the same as the data (10): group, colour
I saw a similar method of graphing and implemented it:
ggplot(PrefSE, aes(x = Day, y = Intake, group = 2)) +
geom_line() +
geom_errorbar(width = 0.1, aes(ymin = Intake-se, ymax = Intake+se)) +
geom_point(shape=20, size=2, fill=c("black")) +
ylim(25,100)
although it did not give me separate groups:
If anyone can help me create separate groups without getting the error messages please help!!
Thank you in advance