Re: [R] xyplot and for loops
Thanks to Andy and Bert for setting me straight! Explicitly printing the xyplot command takes care of the issue. Just didn't dig quite far enough into the documentation. cheers, Dave [EMAIL PROTECTED] wrote: Dave, I think inside the loop you have to explicitly "print" a trellis object, i.e. say print(yplot(tmp.df$y.tmp ~ tmp.df[,i])) If you read the help page for xyplot, look under "Value". Hope this helps, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 Dave Atkins <[EMAIL PROTECTED] gton.edu> To Sent by: [EMAIL PROTECTED] [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] xyplot and for loops 05/04/2004 05:40 PM I'm attempting to use xyplot() within a for() loop to plot the relationship between a DV and a series of predictor variables, split by 2 conditioning variables. However, xyplot() does not "seem" to be recognized within the for() loop; I don't receive any error message, but nothing is plotted and a plotting device is not opened. When I use the generic function plot(), everything works as expected. I'm using R v1.9.0 and lattice v0.9-11. Here's a trivial example: ### create single outcome and two predictors > y.tmp <- rnorm(20) ; x1.tmp <- rnorm(20) ; x2.tmp <- rnorm(20) ### combine into data.frame > tmp.df <- data.frame(y.tmp, x1.tmp, x2.tmp) > tmp.df y.tmp x1.tmp x2.tmp 1 1.5022759 -0.150326662 -1.36627981 [snip] 20 1.2667825 -0.070356651 -0.38433160 ### simple loop calling the columns of tmp.df to specify x variables > for (i in 2:3){ + plot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### works fine for plot() ### try the same with xyplot() > for (i in 2:3){ + xyplot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### nothing happens; no error msg; no plotting device opened > xyplot(tmp.df$y.tmp ~ tmp.df[,2]) ### without loop works fine and plots relationship of x1.tmp and y.tmp Can someone see what I'm missing? Any directions/pointers appreciated. cheers, Dave [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] xyplot and for loops
Dave, I think inside the loop you have to explicitly "print" a trellis object, i.e. say print(yplot(tmp.df$y.tmp ~ tmp.df[,i])) If you read the help page for xyplot, look under "Value". Hope this helps, Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 Dave Atkins <[EMAIL PROTECTED] gton.edu> To Sent by: [EMAIL PROTECTED] [EMAIL PROTECTED] cc at.math.ethz.ch Subject [R] xyplot and for loops 05/04/2004 05:40 PM I'm attempting to use xyplot() within a for() loop to plot the relationship between a DV and a series of predictor variables, split by 2 conditioning variables. However, xyplot() does not "seem" to be recognized within the for() loop; I don't receive any error message, but nothing is plotted and a plotting device is not opened. When I use the generic function plot(), everything works as expected. I'm using R v1.9.0 and lattice v0.9-11. Here's a trivial example: ### create single outcome and two predictors > y.tmp <- rnorm(20) ; x1.tmp <- rnorm(20) ; x2.tmp <- rnorm(20) ### combine into data.frame > tmp.df <- data.frame(y.tmp, x1.tmp, x2.tmp) > tmp.df y.tmp x1.tmp x2.tmp 1 1.5022759 -0.150326662 -1.36627981 [snip] 20 1.2667825 -0.070356651 -0.38433160 ### simple loop calling the columns of tmp.df to specify x variables > for (i in 2:3){ + plot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### works fine for plot() ### try the same with xyplot() > for (i in 2:3){ + xyplot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### nothing happens; no error msg; no plotting device opened > xyplot(tmp.df$y.tmp ~ tmp.df[,2]) ### without loop works fine and plots relationship of x1.tmp and y.tmp Can someone see what I'm missing? Any directions/pointers appreciated. cheers, Dave [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] xyplot and for loops
I'm attempting to use xyplot() within a for() loop to plot the relationship between a DV and a series of predictor variables, split by 2 conditioning variables. However, xyplot() does not "seem" to be recognized within the for() loop; I don't receive any error message, but nothing is plotted and a plotting device is not opened. When I use the generic function plot(), everything works as expected. I'm using R v1.9.0 and lattice v0.9-11. Here's a trivial example: ### create single outcome and two predictors > y.tmp <- rnorm(20) ; x1.tmp <- rnorm(20) ; x2.tmp <- rnorm(20) ### combine into data.frame > tmp.df <- data.frame(y.tmp, x1.tmp, x2.tmp) > tmp.df y.tmp x1.tmp x2.tmp 1 1.5022759 -0.150326662 -1.36627981 [snip] 20 1.2667825 -0.070356651 -0.38433160 ### simple loop calling the columns of tmp.df to specify x variables > for (i in 2:3){ + plot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### works fine for plot() ### try the same with xyplot() > for (i in 2:3){ + xyplot(tmp.df$y.tmp ~ tmp.df[,i]) + } ### nothing happens; no error msg; no plotting device opened > xyplot(tmp.df$y.tmp ~ tmp.df[,2]) ### without loop works fine and plots relationship of x1.tmp and y.tmp Can someone see what I'm missing? Any directions/pointers appreciated. cheers, Dave [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html