[R] mgcv package plot superimposing smoothers

Jef Vlegels Jef.Vlegels at UGent.be
Fri Dec 3 15:49:56 CET 2010

Dear R help list,

I'm fitting a 'variable coefficient model' in the MGCV package and I want to
plot the different smoothers I get for each factor level in one graph. 

So, I do something like this to fit the gam:
Mtest <- gam(outcome ~ s(age, by=as.numeric(gender==0)) +

Then I can plot the smoother for gender=0:
And for gender=1:

But the second plot superimposes the first one. Normally I use 'lines' to
plot just the line from the second plot in the first plot, but this doesn't
seem to work with the plot.gam function. 
Does someone have a solution to plot these two smoothers in one graph, each
with a different color/line type?

Thanks in advance,
Jef Vlegels

More information about the R-help mailing list