简体   繁体   English

画一条垂直线与一条水平线交汇

[英]draw vertical line to meet a horizontal line

I would like to draw a vertical line at a certain/arbitrary point to meet a certain horizontal line: 我想在某个/任意点画一条垂直线以满足某个水平线:

xyplot(Amplification ~ Voltage | Serial_number,
       data = APD[APD$Serial_number==912009897,],
       panel = function(x, ...){
                                panel.xyplot(x, ...);
                                panel.abline(h = 150)
                                panel.abline(v = 350)},
       ylim = c(100,200),
       grid = TRUE 
)

Perfectly both lines will end at the crossing to make it more descriptive. 完美地说,两条线都将在交叉点处结束,以使其更具描述性。 How can I do that? 我怎样才能做到这一点? Thank you! 谢谢!

情节

So, if you want x = 350 and y = 150, as the end of the lines I would go through command 'points' and make two lines, just guessing some safe starting points for both lines: 因此,如果您希望x = 350和y = 150,那么在行的结尾,我将通过命令“ points”并生成两行,只需猜测这两行的一些安全起点即可:

points(c(350,350),c(100, 150), type='l') # the vertical one

points(c(100, 350),c(150, 150), type='l') # the horizontal one

In a more generalised way, you first define your point and after plotting, you get the axis dimensions and make the lines with the actual values: 以一种更通用的方式,您首先定义点,然后在绘制之后获得轴尺寸并使用实际值绘制线:

point <- c(350,150) # point of line crossing
plot(.... ) # your plot
mrs <- par('usr') # axis limits
## Now the lines
points(rep(point[1],2),c(mrs[3], point[2]), type='l')
points(c(mrs[1], point[1]),rep(point[2],2), type='l')

that should do the job. 那应该做的工作。

the lines at the end will make a line between two points, it is something like joining (x1,y1) to (x2,y2). 末尾的线将在两点之间形成一条线,就像将(x1,y1)连接到(x2,y2)一样。 So, with the command par('usr') you will get the starting and ending points of both axis, in a vector of length 4, something like (min(x),max(x),min(y),max(y)). 因此,使用命令par('usr'),您将在长度为4的向量中获得两个轴的起点和终点,例如(min(x),max(x),min(y),max( y))。 so with points you just make a line bettwen (c(x1,x2),c(y1,y2)). 所以用点就可以做成一条直线bettwen(c(x1,x2),c(y1,y2))。 For the vertical one, then your x-coordinate is the same for both points, that's why there is rep(point[1],2), and in the y, it is the value of y and the starting of y axis (that is why it is msr[3], is the third number of the vector), and so on... 对于垂直坐标,则两个点的x坐标都相同,这就是为什么存在rep(point [1],2)的原因,而在y中,它是y的值和y轴的起点(即这就是为什么它是msr [3],是向量的第三个数字),依此类推...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM