im trying to put 3 linear regression results into one graph uing:
equation1=function(x){coef(m1)[2]*x+coef(m1)[1]}
equation2=function(x){coef(m2)[2]*x+coef(m2)[1]+coef(m1)[3]}
equation3=function(x){coef(m3)[2]*x+coef(m3)[1]+coef(m1)[3]+coef(m3)[3]}
ggplot(Behaviour,aes(y=Height,x=Probes,color=Species))+geom_point()+stat_smooth(method="lm", se=FALSE)+xlab("Probes")+ylab("Shore Height")
ggplot(stat_function(fun=equation1,geom="line",color=scales::hue_pal()(2)[1]))+
ggplot(stat_function(fun=equation2,geom="line",color=scales::hue_pal()(2)[2]))+
ggplot(stat_function(fun=equation3,geom="line",color=scales::hue_pal()(2)[3]))
however i keep getting this error:
Error in fortify()
:
! data
must be a <data.frame>, or an object coercible by fortify()
, or a valid <data.frame>-like object coercible by as.data.frame()
.
Caused by error in .prevalidate_data_frame_like_object()
:
! dim(data)
must return an of length 2.
Backtrace:
- ggplot2::ggplot(…)
- ggplot2:::ggplot.default(…)
- ggplot2:::fortify.default(data, …)
- ggplot2:::validate_as_data_frame(model)
- ggplot2:::.prevalidate_data_frame_like_object(data)
Error in fortify(data, …) :
Caused by error in.prevalidate_data_frame_like_object()
:
!dim(data)
must return an of length 2.
im expecting a scatterplot, colour coded for the 3 species mentioned in the code including the lines for linear regression.
Amelia Hearn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.