Use geom_smooth with transformed y

Is there a way to use geom_smooth when the y variable in the formula is converted? For instance:

 #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 get is a line like this:

 myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed))))) 
+5
source share
1 answer

You can put GLM for Gaussian (normally distributed) data and a link to the log. This will allow stat_smooth use and return relevant forecasts.

 (myplot + geom_smooth(method = "glm", formula = y~x, family = gaussian(link = 'log'))) 

enter image description here

+6
source

Source: https://habr.com/ru/post/1203782/


All Articles