我不能找出迴歸線方程,r^2和我用plot函數geom_smooth繪製的線性迴歸的p值。ggplot2:如何獲得迴歸直線方程的值,r^2和p值?
這是我的代碼:
g <- ggplot(data=data.male, aes(x=mid_year, y=mean_tc, colour=data.male$survey_type))
g <- g + geom_point(shape = 20, size =2)
g <- g + geom_smooth(method=lm, na.rm = FALSE, se = TRUE, aes(group=1), colour = "black")
g <- g + theme_gray(base_size=24)
g <- g+ xlab("Year")
g <- g + ylab("Mean serum total cholesterol (mmol/L)")
g <- g + theme(legend.position="bottom")
g <- g + scale_y_continuous(limits=c(3.5,6.5), breaks=c(3.5,4,4.5,5,5.5,6,6.5))
g <- g + scale_x_continuous(limits=c(1980,2015), breaks=c(1980,1990,2000,2010))
g <- g + scale_colour_manual(name = "Survey Type", values= c("Red", "Blue", "Green"))
g
[1]:
正如@Spacedman在他的回答中所說,爲什麼不適合自己的模型並提取必要的數據? – Heroka
如果你看到[這裏]的答案(http://stackoverflow.com/questions/7549694/ggplot2-adding-regression-line-equation-and-r2-on-graph),你也會看到它使用' lm'也在內部。 –
另請參閱:http://stackoverflow.com/questions/10302851/extract-coefficients-from-ggplot2-created-nls-fit –