Reputation: 4877
In ggplot2
, how do I make a stat_function
use the same x scale as the geom layer, for instance scale_x_log10
?
To illustrate the problem, consider this example:
x <- rexp(100)
base <- qplot(x, geom = "density")
base + stat_function(fun = dexp, colour = "red")
So far so good. But now, I add a scale:
base + stat_function(fun = dexp, colour = "red") + scale_x_log10()
Upvotes: 3
Views: 251
Reputation: 4877
The answer seems to be, you can't. There is a predefined order in which ggplot2 does transformations;
Hence, instead of scale transformation, use a coordinate transformation.
base + stat_function(fun = dexp, colour = "red") + coord_trans(x = "log10")
Upvotes: 2