如何制作一个简单的线型图,其中每条线将有不同形状的附加点(geom_point)。这些点应与线条颜色相同。
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")))在下面的图表中,两条线上的点是相同的。
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")当我添加"shape = GROUP“美学时,就会创建两个传说,我需要一个传说:-)
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")我能在解决这个问题方面寻求帮助吗?
发布于 2022-07-10 22:12:48
我们可以使用guide_legend(override.aes = ...并将形状指南设置为none:
要获得填充的形状,只需更改形状0和1:

塑造15和16:

https://ggplot2.tidyverse.org/articles/ggplot2-specs.html
library(ggplot2)
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP, shape = GROUP)) +
geom_line(position = position_dodge(0.3)) +
geom_point(size = 3, position = position_dodge(0.3)) +
scale_shape_manual(values = c(15, 16)) +
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")+
guides(colour = guide_legend(override.aes = list(linetype = c("solid", "solid")
, shape = c(15, 16))),
shape = "none")

发布于 2022-07-10 21:12:55
我认为您可以将aes(shape = GROUP)放在geom_point中,并设置show.legend = F
ggplot(my_data, aes(x = TIME, y = M, group = GROUP, color = GROUP)) +
geom_line(position = position_dodge(0.3)) +
geom_point(aes(shape = GROUP), show.legend = F, 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")

https://stackoverflow.com/questions/72931761
复制相似问题