[R] lattice: strange behavior (?) when using trellis.device(color=FALSE)
Marius Hofert
m_hofert at web.de
Sat Nov 27 09:28:16 CET 2010
Dear David,
thanks for your help. I completely missed the point of trellis.device()... It is probably not the right thing for what I want to achieve. I do not want to open a device or plot the xyplot-object, I just want to create it and save it in a variable. I would like to *not* having to write "col = 1"... several times (as described before) in order to obtain black color for the lines, plot symbols etc.
I looked at the archive again and found a call to lattice.options():
library(lattice)
xyplot. <- function(u) {
lattice.options(default.theme = standard.theme(color = FALSE))
xyplot(u[,2]~u[,1])
}
U <- matrix(runif(20),ncol=2)
b <- xyplot.(U)
xyplot(U[,2]~U[,1])
Now if I type "b", I get the plot without colors. However, since the function call changes the default.theme, the following call xyplot(U[,2]~U[,1]) is also in black/white. Is there a way I can *only* set the color to black/white within/for the function xyplot. ?
Maybe I think of it in the wrong way and shouldn't try to change the color within the function; only when it is plotted. But then I can't simply type "b" and get the right thing.... which I would if I used the "col = 1" options in the call of xyplot
Cheers,
Marius
On 2010-11-27, at 02:38 , David Winsemius wrote:
>
> 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@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
>
More information about the R-help
mailing list