与geom_smooth的对数y [英] Logarithmic y with geom_smooth

查看:66
本文介绍了与geom_smooth的对数y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与此类似:

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'))))

这篇关于与geom_smooth的对数y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆