As you are plotting linear relationship between x and y, you can use geom_smooth()
with method="lm"
.
ggplot(d, aes(x, y)) + geom_point() + geom_smooth(method="lm",se=FALSE)+
scale_y_log10() + scale_x_log10()
UPDATE
It seems that geom_abline()
doesn't have argument untf=TRUE
as for function abline()
.
Workaround would be to use geom_line()
and new data frame in it that contains y values calculated using coefficients of your linear model or using function predict()
.
ggplot(d, aes(x, y)) + geom_point() +
geom_line(data=data.frame(x=d$x,y=coef(fit)[1]+coef(fit)[2]*d$x))+
scale_y_log10() + scale_x_log10()
ggplot(d, aes(x, y)) + geom_point() +
geom_line(data=data.frame(x=d$x,y=predict(fit)))+
scale_y_log10() + scale_x_log10()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…