对于以下数据集,我试图在ggplot上标记SD并突出显示它。
ID S1 S2
1 21.09542 71.06014
2 21.09564 71.06064
2 21.09619 71.06128
2 21.09636 71.06242
2 21.09667 71.06564
2 21.09483 71.06619
2 21.09483 71.06619
1 21.09264 71.06633
3 21.08986 71.06678
3 21.08925 71.06653
3 21.08925 71.06653
1 21.08925 71.06653
and so on...
这是我从数据集link开始的路径 我尝试使用此命令在ggplot上绘制SD:
#Data frame with mean and SD
df4 <- Data %>% group_by(ID) %>% mutate(SD1 = sd(s1)) %>% mutate(SD2 = sd(s2)) %>% mutate(mean_s1 = mean(s1)) %>% mutate(mean_s2 = mean(s2))
我已经通过geom_path()创建了一条路径,现在我想突出显示此路径上的SD。像link这样的东西,突出显示的路径显示路径中的SD。
plt <- ggplot(df4, aes(x = s1, y = s2, colour = ID), pch = 17) +geom_point()
plt + geom_path(data = rbind(cbind(tail(Data.sel, -1), grp = 1:(nrow(Data.sel)-1)),
cbind(head(Data.sel, -1), grp = 2:nrow(Data.sel)-1)),
aes(group = interaction(grp)), arrow= arrow(type = "closed", angle = 12), colour="grey") +
geom_errorbar(aes(x=Latitude, ymin=Longitude-std.latitude, ymax=Longitude+std.longitude))