R 在ggplot中有没有简单的方法来设置垂直线或水平线的限制?
我想绘制R 在ggplot中有没有简单的方法来设置垂直线或水平线的限制?,r,ggplot2,R,Ggplot2,我想绘制geom\u vline或geom\u hline的一部分,代码如下: df <- data.frame(x=1:10,y=1:10) plt <- ggplot(data=df)+ geom_point(aes(x=x,y=y))+ geom_vline(aes(xintercept=x[2]))+ geom_hline(aes(yintercept=y[2])) df您可以使用geom\u-line library(ggplot2) df <- da
geom\u vline
或geom\u hline
的一部分,代码如下:
df <- data.frame(x=1:10,y=1:10)
plt <- ggplot(data=df)+
geom_point(aes(x=x,y=y))+
geom_vline(aes(xintercept=x[2]))+
geom_hline(aes(yintercept=y[2]))
df您可以使用geom\u-line
library(ggplot2)
df <- data.frame(x=1:10,y=1:10)
plt <- ggplot(data=df)+
geom_point(aes(x = x, y = y))+
geom_line(data = data.frame(x = c(2, Inf), y = c(2, 2)), aes(x = x , y = y)) +
geom_line(data = data.frame(x = c(2, 2), y = c(2, Inf)), aes(x = x, y = y))
geom_段
允许您使用geom_段
绘制具有x和y限制的线,您可以将上限设置为Inf
,以确保它们延伸到绘图的边缘获取它!非常感谢。
plt <- ggplot(data=df)+
geom_point(aes(x = x, y = y))+
geom_segment(aes(x = 2 , y = 2, xend = Inf, yend = 2)) +
geom_segment(aes(x = 2 , y = 2, xend = 2, yend = Inf))