I am trying to export the fitted equation, seen as a label in the graph of the example below, to a text file and I am not sure how to approach the problem. The equation is a string (eq.label) in stat I have attempted to output to the console using geom_debug(), which outputs the data points as a tibble, however it does not output the equation. Any suggestions?
library(ggplot2)
library(ggpmisc)
library(gginnards)
library(broom)
x<-rnorm(100,1, 2)
y<-rnorm(100,0.5, 2)
df<-data.frame(x,y)
str(df)
qplot(x,y)
my.formula <- y ~ poly(x, 5, raw = TRUE)
ggplot(df, aes(x, y) )
+ geom_point(colour = "blue")
+ stat_smooth(method = "lm",formula = my.formula)
+ stat_poly_eq(formula = my.formula, eq.with.lhs = "italic(y)~`=`~",
eq.x.rhs = "~italic(x)",aes(label = paste(..eq.label..,
..rr.label.., sep = "~~~")), parse = TRUE, size = 4)
+ labs(x="x", y="y")+ theme(legend.position="none",
axis.text=element_text(size=14), axis.title=element_text(size=14))