Is there a way to use geom_smooth
when the y
variable in the formula is transformed? For example:
#This works:
myplot <- qplot(speed, dist, data=cars)
(myplot + geom_smooth(method="lm", formula=y~log(x)))
#does not work
(myplot + geom_smooth(method="lm", formula=log(y)~x))
What I am after is a line like this:
myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed)))))
The warning geom_smooth() using formula 'y ~ x' is not an error. Since you did not supply a formula for the fit, geom_smooth assumed y ~ x, which is just a linear relationship between x and y.
geom_smooth() and stat_smooth() are effectively aliases: they both use the same arguments. Use stat_smooth() if you want to display the results with a non-standard geom.
You can use the geom_smooth layer to look for patterns in your data. We use this layer to Plot two continuous position variables in the graph. The basic setting for described geometry is shown in the following plot.
Example 2: Modify Level of Confidence Interval By default, geom_smooth() uses 95% confidence bands but you can use the level argument to specify a different confidence level.
You can fit a GLM for Gaussian (normally distributed) data and a log link. This will allow stat_smooth
to use and return the appropriate predictions
(myplot + geom_smooth(method = "glm", formula = y~x,
family = gaussian(link = 'log')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With