Hello everyone, I'm very new to R coding and I've been doing exercises to help myself learn the language.
I'm trying to use ggplot2 to help plot models of some data and I'm having some issues.
This is my data, x1 is the input and y1 the output:
y1=c(10.05,1.5,-1.234,0.02,8.03)
x1=c(-3,-1,0,1,3)
When I try to model the data using a 1st degree polynomial, it all works fine until I try to plot using ggplot where I get a huge zig zag, I'll paste my coding and if someone could help me out that would be much appreciated!
data1<-data.frame(y1,x1)
Fit1<-lm(y1~x1,data = data1)
yhat1<-predict(Fit1,data1)
Then when I try to plot the fit using gg plot:
ggplot(data1, aes(x=x1, y=y1)) +geom_point(size=3, shape=19,color="red") + * geom_smooth(method="lm",formula = y1~x1, data=data1,se=FALSE,linetype="solid", color = "blue", size = 3)
I get the error : Warning message:
'newdata' had 80 rows but variables found have 5 rows
Along with the zigzag.
Thank you