How to make a simple line graph where each line will have additional points of different shapes (geom_point). These points should be of the same color as the lines.
my_data <- data.frame(
TIME = c("T1-3","T3-5","T6-8","T8-10","T1-3","T3-5","T6-8","T8-10"),
GROUP = c("A","A","A","A","B","B","B","B"),
M = as.numeric(c("7.52","7.85","8.6","9.2","7.55","7.85","8.61","9.22")),
SD = as.numeric(c("0.19","0.16","0.19","0.26","0.2","0.22","0.2","0.26")))
In the graph below, the points are the same on both lines.
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP)) +
geom_line(position = position_dodge(0.3)) +
geom_point(position = position_dodge(0.3)) +
scale_shape_manual(values = c(0, 1)) +
geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
theme_light() +
theme(legend.position = "top")
When I add the "shape = GROUP" aesthetic, two legends are created and I need one legend :-)
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP, shape = GROUP)) +
geom_line(position = position_dodge(0.3)) +
geom_point(position = position_dodge(0.3)) +
scale_shape_manual(values = c(0, 1)) +
geom_errorbar(aes(x = TIME, ymin = M-SD, ymax = M+SD), width = .2, position = position_dodge(0.3)) +
labs(col = "Group of hurdlers", x = "Phase distance", y = "Time (seconds)") +
theme_light() +
theme(legend.position = "top")
Can I ask for help in solving this problem?



