一种方法是提供 新 数据到后续调用 geom_path 。既然你在谈论原始帧中的连接点,我认为不需要创建一个新的帧,只需索引我们想要的列。一件好事(有 ggplot2 )这就是美学( aes(x,w) )没有改变(虽然更新它们 data= 不是问题)。
geom_path
ggplot2
aes(x,w)
data=
h + geom_path(data=wts[c(4,6),], color="blue") + geom_path(data=wts[c(1,4,2,5,3),], color="red")
我认为你错误输入了一个坐标,应该 (3,118) 是 (3,114) ?如果没有,那么只需生成一个新帧并包含它。
(3,118)
(3,114)
此外,由于您在两行中都包含至少一个点,因此我不认为可以通过分组轻松解决。为此,我推断您将定义第三个变量,为某些特定组分配一些点。您可以通过复制有问题的点来解决这个问题,如下所示。您还需要考虑点的顺序:
wts2 <- rbind(wts, wts[4,]) wts2$grp <- c(2,2,2,2,2,1,1) wts2$ord <- c(1,4,2,5,3,6,7) # original plot, just changing wts for wts2[wts2$ord,] h <- ggplot(data=wts2[wts2$ord,], aes(x,w)) + geom_point(colour="blue") + labs(title="Breaches",x = "Quarter", y= "Number of Breaches") + theme_minimal() + xlim(1,5) + ylim(0,120) # an alternative to my first answer h + geom_path(aes(group = grp, color = factor(grp)))