Marius Hofert
2010-Nov-26 23:35 UTC
[R] lattice: strange behavior (?) when using trellis.device(color=FALSE)
Dear expeRts, I am not sure if I found a bug... I would like to create a function that itself creates a lattice plot without colors. Following http://www.mail-archive.com/r-help at r-project.org/msg64699.html I use trellis.device() to set the colors to FALSE. Whenever I call the minimal example below *with* trellis.device(), Quartz opens a window (I am working on a MAC), which it shouldn't, since I only want to create the plot, but do not intend to "print" it. Moreover, if I check the value of b, it prints the plot (which is correct) but still with colors. Without the trellis.device() call, it works fine (but of course the plot is again colored)... The reason why I would like to use trellis.device() within a function is that the plot contains a panel.function which contains many calls to panel.xyplot() and I do not want to write "col = 1" (e.g.) all the time... Cheers, Marius library(lattice) xyplot. <- function(u) { trellis.device(color = FALSE) xyplot(u[,2]~u[,1]) } U <- matrix(runif(20),ncol=2) b <- xyplot.(U)
David Winsemius
2010-Nov-27 01:38 UTC
[R] lattice: strange behavior (?) when using trellis.device(color=FALSE)
On Nov 26, 2010, at 6:35 PM, Marius Hofert wrote:> Dear expeRts, > > I am not sure if I found a bug... > I would like to create a function that itself creates a lattice plot > without > colors. Following http://www.mail-archive.com/r-help at r-project.org/msg64699.html > I use trellis.device() to set the colors to FALSE. Whenever I call > the minimal > example below *with* trellis.device(), Quartz opens a window (I am > working on a > MAC), which it shouldn't,Wrong. Please look at the default for the "device" argument in the help page of trellis.device().> since I only want to create the plot, but do not intend > to "print" it. Moreover, if I check the value of b, it prints the > plot (which > is correct) but still with colors. > Without the trellis.device() call, it works fine (but of course the > plot is > again colored)... > The reason why I would like to use trellis.device() within a > function is that > the plot contains a panel.function which contains many calls to > panel.xyplot() > and I do not want to write "col = 1" (e.g.) all the time... > > Cheers, > > Marius > > library(lattice) >Just take the trellis.device() line out of that function. Or specify a proper device call as an argument to device= ....> xyplot. <- function(u) {# trellis.device(color = FALSE)> > xyplot(u[,2]~u[,1]) > } > > U <- matrix(runif(20),ncol=2) > > b <- xyplot.(U)str(b)>David Winsemius, MD West Hartford, CT
ottorino
2010-Nov-27 11:00 UTC
[R] lattice: strange behavior (?) when using trellis.device(color=FALSE)
Il giorno sab, 27/11/2010 alle 00.35 +0100, Marius Hofert ha scritto:> The reason why I would like to use trellis.device() within a function > is that > the plot contains a panel.function which contains many calls to > panel.xyplot() > and I do not want to write "col = 1" (e.g.) all the time...Why not to use a theme like BW.theme <- list(strip.background = list(col = "gray90"), strip.shingle = list(col=c("gray75")), layout.heights = list(strip = c(1,1)), axis.text = list(cex = 0.8), superpose.symbol=list(col=1, pch=20) ) xyplot(V1~V2, par.settings = BW.theme)
Gabor Grothendieck
2010-Nov-27 12:42 UTC
[R] lattice: strange behavior (?) when using trellis.device(color=FALSE)
On Fri, Nov 26, 2010 at 6:35 PM, Marius Hofert <m_hofert at web.de> wrote:> I am not sure if I found a bug... > I would like to create a function that itself creates a lattice plot without > colors. Following http://www.mail-archive.com/r-help at r-project.org/msg64699.html > I use trellis.device() to set the colors to FALSE. Whenever I call the minimal > example below *with* trellis.device(), Quartz opens a window (I am working on a > MAC), which it shouldn't, since I only want to create the plot, but do not intend > to "print" it. Moreover, if I check the value of b, it prints the plot (which > is correct) but still with colors. > Without the trellis.device() call, it works fine (but of course the plot is > again colored)... > The reason why I would like to use trellis.device() within a function is that > the plot contains a panel.function which contains many calls to panel.xyplot() > and I do not want to write "col = 1" (e.g.) all the time...Create a wrapper to xyplot that has the arguments preset to what you want. Using the built in BOD data frame: library(lattice) f <- function() { xyplot. <- function(..., col = 1) xyplot(..., col = col) xyplot.(demand ~ Time, BOD) } b <- f() b The above works in this example but depending on the specifics of the actual application you may need this instead: xyplot. <- function(..., col = 1) eval.parent(substitute(xyplot(..., col = col)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com