簡體   English   中英

ggplot2:如何獲取回歸線方程的值r ^ 2和p值?

[英]ggplot2: how to get values for the regression line equation, r^2 and p value?

我無法解決如何使用函數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  

[1]:

不要使用繪圖功能進行建模。 使用lm函數擬合模型。

然后使用summary方法來獲取您需要了解的有關擬合的所有信息。

您應該得到與繪圖函數相同的結果,我懷疑該函數在內部使用lm

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM