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

From: Daniel Malter <daniel_at_umd.edu>
Date: Wed, 09 Jul 2008 14:26:37 -0400


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.

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. Received on Wed 09 Jul 2008 - 19:04:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 09 Jul 2008 - 19:31:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive