ggplot2点之间的垂直线

use*_*113 3 r ggplot2

我是新手,ggplot2无法弄清楚如何绘制之间的垂直虚线灰线

沿x轴的点/点.这是我的示例代码:

d1 <- runif(10,10,15)

d2 <- runif(10,25,30)

d3 <- rep(1:10,2)

df <- data.frame(x = d3, y = c(d1,d2))

ggplot(df, aes(x=x, y=y)) +

geom_point()
Run Code Online (Sandbox Code Playgroud)

Sve*_*ein 15

如果您的实际数据结构与您的示例中使用的数据类似,则只需添加geom_line(aes(group = d3))到绘图中.

ggplot(df, aes(x=x, y=y)) +  
 geom_point() + geom_line(aes(group = d3))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述