ggplot2:如何获得回归线方程的值,r ^ 2和p值?

Nad*_*iah 2 r linear-regression ggplot2

我不知道如何得到回归线方程,我用函数geom_smooth绘制的线性回归的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  
Run Code Online (Sandbox Code Playgroud)

[1]:

Spa*_*man 6

不要使用绘图功能进行建模.使用该lm功能调整模型.

然后使用该summary方法获取有关拟合的所有信息.

你应该得到与绘图功能相同的结果,我怀疑它是在lm内部使用的.