点与ggplot2之间的垂直线 [英] Vertical lines between points with ggplot2
本文介绍了点与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()
解决方案
如果您的实际数据的结构与您示例中使用的数据类似, $ b
geom_line(aes(group = d3))
ggplot(df,aes(x = x,y = y))+
geom_point()+ geom_line(aes(group = d3))
I am new to ggplot2
and cannot figure out how to draw vertical dotted grey lines between
the points/dots along the x-axis. Here's my example code:
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()
解决方案
If your actual data is structured like the one used for your example, just add geom_line(aes(group = d3))
to the plot.
ggplot(df, aes(x=x, y=y)) +
geom_point() + geom_line(aes(group = d3))
这篇关于点与ggplot2之间的垂直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文