2014-10-01 49 views
5

當公式中的y變量被轉換時,有沒有辦法使用geom_smooth?例如:使用geom_smooth進行轉換y

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

回答

6

可以適應高斯一GLM(正態分佈)數據和日誌鏈接。這將允許stat_smooth使用,並返回相應的預測

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

enter image description here