I've been trying to plot some data and add a third order polynomial trend line. I'm using the lm() and coef() functions to obtain a model for my data and then plot with ggplot.
Here is the relevant code:
Bytes is the name of my dependent variable (y). Resolution is the name of my independent variable (x).
model = lm(Bytes~poly(Resolution, 3), averaged_frame) print(coef(model)) library(ggplot2) plot = ggplot(averaged_frame, mapping = aes(x = Resolution, y = Bytes)) + geom_point() + stat_smooth(method="lm", formula = y~poly(x, 3), se = FALSE) However, when I take the coefficients from print(coef(model)):
(Intercept) poly(Resolution, 3)1 poly(Resolution, 3)2 poly(Resolution, 3)3 0.3392046 0.3686154 0.2504288 0.1274490 And transpose them into a function:
f(x)=0.1274490x^3+0.2504288x^2+0.3686154x+0.3392046 And graph it, it looks completely different to the plot on ggplot.
I'm wondering what I am doing wrong here or how I might get an equation from the line in ggplot.



raw = TRUEinpoly. That's why you get a different curve.