Re: [R] xyplot and for loops

About this list Date view Thread view Subject view Author view Attachment view

From: Dave Atkins (datkins@u.washington.edu)
Date: Wed 05 May 2004 - 09:21:37 EST


Message-id: <40982581.60901@u.washington.edu>


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

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

______________________________________________
R-help@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


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:07 EST