2014-10-01 12 views
5

C'è un modo per utilizzare geom_smooth quando la variabile y nella formula viene trasformata? Per esempio:Utilizzare geom_smooth con trasformato 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)) 

Quello che sto dopo è una linea come questa:

myplot + geom_line(aes(x=speed, y=exp(predict(lm(log(dist)~speed))))) 

risposta

6

È possibile montare un GLM per gaussiana (distribuzione normale) di dati e un collegamento log. Questo permetterà stat_smooth da usare e restituire le previsioni adeguate

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

enter image description here

Problemi correlati