SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
how to join two nls graphs ??? [ Reply ]
By: Carlos Minguez on 2021-05-14 11:08
[forum:48943]
Hello:

I have two databases that measure the times a cow chews with heat (Q1) and without heat (Q4).

I generate the same sinus model:

mod.RumiQ1 <-nls(Rumination ~ a + b*sin(c*Hour-d)+e*cos(f*Hour-g),data=datosQ1,start=list(a =23.5, b = 6, c=3.1, d=9, e=-2.5, f=0.8,g=1))
co<-coef(mod.RumiQ1 )
co
#co
# a b c d e f g
#23.13338 -4.33017 0.33730 97.53357 -5.14952 0.50374 -1.82722

and plot the curve as:

ggplot(datosQ1, aes(x=Hour, y=Rumination))+

# geom_point()+

geom_smooth(method="nls", se=FALSE,

method.args=list(formula=y~ a + b*sin(c*x-d)+e*cos(f*x-g),

start=c(a=23.13338,b= -4.33017,c= 0.33730,d= 97.53357,e= -5.14952, f=0.50374, g= -1.82722 )) )


Now, with Q4 data:

mod.RumiQ4 <-nls(Rumination ~ a + b*sin(c*Hour-d)+e*cos(f*Hour-g),data=datosQ4,start=list(a =22, b = 5, c=3, d=9, e=-3.3, f=1,g=1.5))
co<-coef(mod.RumiQ4 )
co
# a b c d e f g
#22.03420 0.88497 1.89659 -11.66763 -3.35122 1.08926 3.51036

and plot with:

ggplot(datosQ4,

aes(x=Hour, y=Rumination))+

# geom_point()+

geom_smooth(method="nls", se=FALSE,

method.args=list(formula=y~ a + b*sin(c*x-d)+e*cos(f*x-g),

start=c(a=22.03,b= 0.88,c= 1.89,d= -11,e= -3, f=1.00, g= 3.51)) )

I want to join the two curves in the same graph to compare them, but I don't know how to do it.

thanks in advance

Thanks to:
Vienna University of Economics and Business Powered By FusionForge