[英]How to find y-axis values given x-axis for multiple graphs
I have a simple question that I don't know the answer to.我有一个简单的问题,我不知道答案。
Assume having multiple graphs on a plot. I would like to see the exact y-values on all graphs given a specific x.假设在 plot 上有多个图表。我想在给定特定 x 的情况下查看所有图表上的确切 y 值。
Here is a sample R code:这是一个示例 R 代码:
x1=c(1,5,7,9,15)
y1=c(50,30,43,33,12)
x2=c(1,3,5.5,6,15)
y2=c(20,55,44,38,10)
plot(x1,y1,type="o",ylim=c(1,60))
points(x2,y2,type="o")
abline(v=c(2.5,4,6,10))
My question is how I can find the exact y-value for any vertical line crossing the plots?我的问题是如何找到穿过地块的任何垂直线的确切 y 值?
You can create functions that will tell you the values with approxfun
.您可以创建函数来告诉您
approxfun
的值。
NewPoints = c(2.5,4,6,10)
f1= approxfun(x1,y1)
f2= approxfun(x2,y2)
Now the values that you want are: f1(NewPoints)
and f2(NewPoints)
.现在您想要的值是:
f1(NewPoints)
和f2(NewPoints)
。 You can see this by plotting:你可以通过绘图看到这一点:
points(NewPoints, f1(NewPoints), pch=16, col="red")
points(NewPoints, f2(NewPoints), pch=16, col="blue")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.