[R] problem with log axis

Ben Bolker bolker at ufl.edu
Thu Nov 1 19:17:52 CET 2007




R Heberto Ghezzo, Dr wrote:
> 
> Hello,
> if I do:
>   x <- c(0.5,1,3,6,10,20,40)
>   y <- 10-log(x)+rnorm(7,0,0.05)
>   r1 <- lm(y ~ log(x))
>   plot(log(x),y)
>   abline(r1)
> #
> I get a nice plot with the regression line almost over the points.
> but:
>   plot(x,y,log="x")
>   abline(r1)
> gives me exactly the same plot for the points but the regression line
> is completely off !
> I would like the plot with the real values of X on the axis, not the
> log(X)
> can somebody tell me why the "abline" is not correct in the second case?
> Thanks
> H.Ghezzo
> 
> 

  Because by default abline just puts a line with the corresponding
intercept
and slope on the plot, without paying attention to axes transformations.
There is an untf ('untransformed') argument you can set, but in this case
it doesn't work -- maybe designed for y-axis transformation and not
x-axis transformation, hence a bug?  In any case, you can get what
you want with predict() ...

  [If you have time to explore the untf issue further and decide whether
it warrants a bug report, that would be great -- I don't have time right
now]  

plot(x,y,log="x")
abline(r1)
abline(r1,untf=TRUE,col=2)
abline(r1,untf=FALSE,col=3)  ## ??
lines(x,predict(r1),col=4)

-- 
View this message in context: http://www.nabble.com/problem-with-log-axis-tf4733049.html#a13534429
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list