I sent this to the list last week, and haven't seen it pop up. Either I deleted it when it did appear, or possibly it was destroyed as spam...? If it did appear and I somehow missed it, appologies. In a nutshell, can the function FUN supplied to by() deduce what level of factor by() was on when FUN was called? I've been digging through the functions, and can't see where the distinction is made so that get() with a suitable "where=x" argument could help. Cheers Jason ----- Forwarded message from Jason Turner <jasont at indigoindustrial.co.nz> ----- ... I'm using by() to call pairs(), and would like to put the factor level into the title. A toy example would be something like:> d1 <- data.frame(rnorm(100),rt(100,2),sin(1:100)) > levs <- as.factor(rep(1:5,20)) > levels(levs) <- c("low","med-lo","med","med-hi","high") > by(d1,levs,pairs)Is there an elegant way to get "low"..."high" in the main title for each plot, without binding "levs" to the data sent to a custom plot function? ... -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Sun, Mar 17, 2002 at 09:23:41PM -0500, james.holtman at convergys.com wrote:> You can reference the first entry in the column in the function. See the > example below:Um, thanks, but I provided a similar example, saying this was what I didn't want to do. I can live with "you're stuck with that way". ...> Jason Turner <jasont at indigoindustrial.co.nz>@stat.math.ethz.ch on > 03/17/2002 13:41:13...> > d1 <- data.frame(rnorm(100),rt(100,2),sin(1:100)) > > levs <- as.factor(rep(1:5,20)) > > levels(levs) <- c("low","med-lo","med","med-hi","high") > > by(d1,levs,pairs) > > Is there an elegant way to get "low"..."high" in the main title for > each plot, without binding "levs" to the data sent to a custom plot^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^> function?I just thought that was a bit too specific for what I wanted. I was hoping for a direct evaluation within FUN (most likely by by back-refencncing, using get(somevar,which=-x), where somevar and -x are the mystery to me). Saves writing a custom wrapper to "plot" each time I want a new type of plot, for example. However, since by() winds up calling lapply(), this looks tricky. Cheers Jason -- Indigo Industrial Controls Ltd. 64-21-343-545 jasont at indigoindustrial.co.nz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 18 Mar 2002, Jason Turner wrote:> I sent this to the list last week, and haven't seen it pop up. Either > I deleted it when it did appear, or possibly it was destroyed as > spam...? If it did appear and I somehow missed it, appologies.[snip]> I'm using by() to call pairs(), and would like to put the factor > level into the title. A toy example would be something like: > > > > d1 <- data.frame(rnorm(100),rt(100,2),sin(1:100)) > > levs <- as.factor(rep(1:5,20)) > > levels(levs) <- c("low","med-lo","med","med-hi","high") > > by(d1,levs,pairs) > > Is there an elegant way to get "low"..."high" in the main title for > each plot, without binding "levs" to the data sent to a custom plot > function?One way is to pass the level info with the data to be plotted:> d2 <- cbind(d1, levs) > by(d2,levs,function(x){ tmp <- levels(x[,4])[x[1,4]] ;+ pairs( x[,1:3], main=paste("Level:",tmp) ) } ) hope this helps, -- Greg Snow, PhD Office: 223A TMCB Department of Statistics Phone: (801) 378-7049 Brigham Young University Dept.: (801) 378-4505 Provo, UT 84602 email: gls at byu.edu -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._