This question is similar to this one: Use geom_smooth with transformed y
In fact, it's the same one, it's just that the solution provided there no longer works.
What I want to do is plot a geom_smooth that has log(y) on the y side of the formula. If done directly in the formula
argument, it gives a strange result. So, I will use the same example used in the question that I mentioned:
#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))
#no longer works:
(myplot + geom_smooth(method = "glm", formula = y~x,
family = gaussian(link = 'log')))
What I am after is a line like this:
myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed)))))
Yes, you're right, it seems the necessary syntax has changed a bit:
(myplot + geom_smooth(method = "glm", formula = y~x,
method.args = list(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