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: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
Dave Atkins
<datkins at u.washin
gton.edu> To
Sent by: r-help at stat.math.ethz.ch
r-help-bounces at st 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
datkins at u.washington.edu
______________________________________________
R-help at stat.math.ethz.ch 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