I have a series of csv files that I am plotting a 3rd order polynomial regression per csv file.
I set the directory and all .csv files within that directory:
setwd("tester/results")
filenames = dir(pattern="*.csv")
I then iterate through the files and plot volume against time with a 3rd order polynomial 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)))}
Thus, giving
I now wish to add the formula of the lm
function I have plotted on the graph with the r2
value.
From this SO question, I tried:
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))}
However, as you can see from the output, the label is not a 3rd order polynomial