两点:
df.x <- c(0.0014, 0.0027)
df.y <- c(17.38, 22.49)
我想知道 y 在 x==0.002 处。 线性插值得出 19.74。
线性图显示交点:
plot(df.x, df.y, type="b", xlim=c(0.001,0.005), ylim=c(10,30))
abline(v=0.002)
abline(h=19.74)
但是,将 x 轴设置为对数,两点之间的线在 y>19.74 处与 x=0.002 相交:
plot(df.x, df.y, log="x", type="b", xlim=c(0.001,0.005), ylim=c(10,30))
abline(v=0.002)
abline(h=19.74)
我完全不知道 y 方向移动的原因。
我玩过:untf in abline(), par(), log10()
原因是对数变换不是线性变换。因此,需要在对数变换下再次进行插值。
approx(log(df.x),df.y,xout=log(0.002))
$x
[1] -6.214608
$y
[1] 20.15507
情节:
plot(df.x, df.y, log="x", type="b", xlim=c(0.001,0.005), ylim=c(10,30))
abline(v=0.002)
abline(h=20.15507)
您还没有按照公式绘制曲线,而是绘制了两个点(通过对数刻度定位),然后用直线将它们连接起来。对比:
# your data
df <- data.frame(x = c(0.0014, 0.0027),
y = c(17.38, 22.49))
#interpolate 100 points
df2 <- data.frame(x = seq(from = df$x[1],
to = df$x[2],
length.out = 1000),
y = seq(from = df$y[1],
to = df$y[2],
length.out = 1000))
plot(df2, log="x", type="b", xlim=c(0.001,0.005), ylim=c(10,30))
abline(v=0.002)
abline(h=19.74)