In addition to Ben's reply, you have a few other options:
# Option 1: Transform x in the ggplot() call; the x-axis
# will then be in the log scale
ggplot(newdf, aes(x = log(x), y = y)) + geom_point() +
geom_smooth(method = lm)
# Option 2: Use the trans = option of scale_x_continuous()
ggplot(newdf, aes(x = x, y = y)) + geom_point() +
geom_smooth(method = lm) +
scale_x_continuous(trans = "log")
In options 1 and 2, both transform x to the log scale before computing
the axes. The difference between the two is the set of default breaks;
you can use the breaks = argument in scale_x_continuous() to define
your own.
Option 3 applies a coordinate transformation, which occurs after the
original scales have been drawn. The effect is to warp the original
scaling on the x-axis to a logarithmic one as well as the shape of the
fitted model. You can use this to see the connection between Ben's
solution and the two given above:
ggplot(newdf, aes(x = x, y = y)) + geom_point() +
geom_smooth(method = lm, formula = y ~ log(x)) +
coord_trans(xtrans = "log")
Dennis
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> --- You received this message because you are subscribed to the Google
> Groups "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.