## I have a problem of scales which might not be solvable. In a nut
shell, I want to plot two variables where I expect that plotting them
on a log scale will produce a linear relationship. What I am having
trouble doing is plotting a figure with a log scale and a line from a
regression that follows that relationship. I can one or the other but
not both. I've made trivial example (which is I admit a bit
ridiculous) but serve to highlight my problem.
## Need ggplot2 and a dataframe
require(ggplot2)
df <- data.frame(x=1:1000,y=log(x), z=c("A","B"))
## So say I have this relationship
ggplot(df, aes(x=x, y=y)) +
geom_point()+
facet_wrap(~z)
## And if I plot it on log scales using coord_trans, it a presented with a
## linear trend. But if I try to add a regression line with stat_smooth,
## I am given the regression line of the previous relationship using the
## non-transformed scales. What I am especially after here is those nice\
## log scales on the x axis
ggplot(df, aes(x=x, y=y)) +
geom_point()+
stat_smooth(method="lm") +
coord_trans(x="log")+
facet_wrap(~z)
## If I log the actual variable, then the regression is performed on
the right data
## but the x scale is a log scale like the above plot
ggplot(df, aes(x=log(x), y=y)) +
geom_point()+
stat_smooth(method="lm") +
facet_wrap(~z)
## I realized that ggplot2 and R are doing exactly what I am telling
them to do here but I am wondering
## if there is a way to accomplish this plot with log scales and the
post-transformed regression line.
## Thanks in advance!
Sam
I think you are looking for scale_y_log() instead of coord_trans()
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry....@inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] Namens Sam Albers
Verzonden: vrijdag 27 januari 2012 18:45
Aan: ggplot2
Onderwerp: Log scales (coord_trans) and a regression line (stat_smooth)
Hello all,
## Thanks in advance!
Sam
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2