[R] plot gam "main effect functions" in one graph

Daniel Malter daniel at umd.edu
Wed Jul 9 20:26:37 CEST 2008


Hi, there may be a more elegant way of doing this, but at least it works.
You have to be careful about putting the same axis limits in both graphs and
to use axis-labels in only one of them.

##generate data
x1=c(1:100)
e1=rnorm(100,0,10)
e2=rnorm(100,0,30)
x1=x1+e1
x2=x1+e2
y1=100+x1+0.025*x1^2+e1
y2=100+x1+0.025*x1^2+e2

##run gam

library(mgcv)
reg1=gam(y1~s(x1))
reg2=gam(y2~s(x2))

##plot
plot(reg1,col="blue",xlim=c(-70,200),ylim=c(-300,400),xlab="x",ylab="y")
par(new=TRUE)
plot(reg2,col="red",xlim=c(-70,200),ylim=c(-300,400),xlab=NA,ylab=NA)

Best,
Daniel

-------------------------
cuncta stricte discussurus
-------------------------

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Pancrazio Bertaccini
Gesendet: Wednesday, July 09, 2008 6:37 AM
An: R-help at r-project.org
Betreff: [R] plot gam "main effect functions" in one graph

Dear R users,
I have a question about the plot with the package gam.
I need to plot different main effect functions, related to different gam
models, in the same graphics (i.e. the same covariate about different
models).
I used the plot.gam e preplot.gam documentations. Using preplot.gam I can
plot the single function but I'm not able to put all the functions together.
Does anybody can help me.
Thank you in advance.

Pancrazio Bertaccini,
PhD student,
Università di Torino - Department of Statistics and Applied Mathematics

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list