之前偷懶,每次回歸擬合之后,添加擬合函數(shù)和R2都不積極,用annotate函數(shù)暴力加,浪費很多時間
今天學(xué)習(xí)了一個包ggpmisc,可以進行擬合函數(shù)的添加,并標注R2,效率up!
Step1:使用如下代碼實現(xiàn),R2的表達。
library(ggpmisc)
my.formula <- y~x
ggplot(data=odata,aes(x=GPP7,y=rs25mass,color=species))+
theme(panel.border = element_rect(fill=NA,color="black", size=1, linetype="solid"))+
theme(panel.grid =element_blank())+
theme(panel.background = element_rect(fill = "white"))+
geom_point(aes(color=species))+
geom_smooth(formula = my.formula,method = "lm",se=T)+
stat_poly_eq(formula = my.formula)
效果圖如下

image.png
然后仔細看了一下ggpmisc這個包,發(fā)現(xiàn)真的很有用!
R-ggpmisc|回歸曲線添加回歸方程,R2,方差表,香不香? - 知乎 (zhihu.com)
這個兄臺寫的文章,很清楚的說明了這個包如何使用。
有一個小part沒有搞懂,關(guān)于aes label部分……稍后再看