I’m using ggplot
to make a geom_point()
graph, and I’m using stat_summary()
to show mean values for each category and an interconnecting line. I’ve had to reorganise the categories on the x-axis using scale_x_discrete()
, but the line between the mean values is connecting my data points in the wrong order. So, I’m writing my code like this:
Baseline1 <- ggplot(data=smalllongdatabaseline, aes(x=Condition,
y=AVDScore)) +
geom_point(aes(colour=as.factor(Condition)), size=1,
show.legend=FALSE) +
scale_colour_brewer(palette = "RdBu") +
stat_summary(aes(y = AVDScore, group=Condition), fun=mean,
colour="orange", geom="path", group=4) +
stat_summary(aes(y = AVDScore,group=Condition), fun=mean,
colour="black", fill="orange", geom="point", size=2,
shape=22, group=4) +
theme_classic() +
scale_y_continuous(name="Frequency", breaks=seq(0,35,5), limits=c(0,35),
expand=c(0,0)) +
scale_x_discrete(limits=c("0.5 cpd + Baseline", "0.5 cpd + 0.5 KHz",
"0.5 cpd + 4 KHz", "0.5 cpd + 8 KHz")) +
labs(x = "Stimulus Condition", y = "Mean Score")
And my output looks like this:
Can anyone help me to get the data points to connect in the correct order? I need to keep the categories on the x-axis in that order.
I can't really find any suggestions for this issue online. Someone suggested that the grpup=4 within stat_summary() should be group=Condition, but that returns an error message saying Obkect 'Condition' not found.