1

Two points:

df.x <- c(0.0014, 0.0027)
df.y <- c(17.38, 22.49)

I want to know y at x==0.002. Linear interpolation gives 19.74.

A linear plot shows the intersection:

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)

However, setting the x-axis to logarithmic, the line between the two points crosses x=0.002 at y>19.74:

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)

I have absolutely no idea about the reason of this shift in y-direction.

I played around with: untf in abline(), par(), log10()

2 Answers 2

3

You haven't plotted a curve following a formula, you've plotted two points (positioned by the log scale) then connected them with a straight line. Contrast:

# your data
df <- data.frame(x = c(0.0014, 0.0027),
                 y = c(17.38, 22.49))

#interpolate 1000 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)

gives
enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

The reason is logarithm transformation is not a linear transformation. Therefore, you need to do the interpolation again under logarithm transformation.

approx(log(df.x),df.y,xout=log(0.002))
$x
[1] -6.214608

$y
[1] 20.15507

plot:

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)

1 Comment

In my case, the plot is only for visualisation. The interpolation needs to be linear. Anyway, thank you for your suggestion!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.