使用geom_smooth和变换后的y [英] Use geom_smooth with transformed y
本文介绍了使用geom_smooth和变换后的y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当公式中的 y
变量被转换时,有没有办法使用 geom_smooth
例如:
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))
myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed)))))
推荐答案
正常分布式)数据和日志链接。这将允许 stat_smooth
使用并返回适当的预测结果
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')))
这篇关于使用geom_smooth和变换后的y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文