0
我有一系列csv文件,我繪製每個csv文件的三階多項式迴歸。添加回歸方程和r2繪製在ggplot2與R
我設置的目錄和目錄中的所有文件的.csv:
setwd("tester/results")
filenames = dir(pattern="*.csv")
然後我通過對時間的文件和情節的體積具有3階多項式lm
迭代。
for (i in 1:length(filenames)) { tmp <-read.csv(filenames[i]); print(ggplot(aes(x = Volume, y = time), data = tmp) + geom_point(aes(color = id)) + geom_smooth(aes(color = id), method= "lm", se = F, formula=y ~ poly(x, 3, raw=TRUE)))}
因此,給予
我現在要添加的lm
功能我已在與r2
值的曲線繪製的公式。
從這個SO question,我想:
for (i in 1:length(filenames)) { tmp <-read.csv(filenames[i]); print(ggplot(aes(x = Volume, y = time_normalised), data = tmp) + geom_point(aes(color = id)) + geom_smooth(aes(color = id), method= "lm", se = F, formula=y ~ poly(x, 3, raw=TRUE)) + stat_smooth_func(geom="text",method="lm",formula=y~poly(x,3,raw=TRUE),hjust=0,parse=TRUE))}
然而,正如你可以從輸出中看到,標籤是不是一個3階多項式
功能'「stat_smooth_func」'是不是在GGPLOT2庫,但是應該從要點中添加或從SO問題,你提供了@kdauria答案提供的鏈接coppied。 –
對!但是,問題依然存在。標籤看起來不正確 – LearningSlowly
函數'「stat_smooth_func」'僅用於第一個或第二個迴歸而不是第三個。您必須修改此代碼才能使用此功能。 –