[R] manipulating colors in lattice

Deepayan Sarkar deepayansarkar at yahoo.com
Sat Apr 20 20:19:57 CEST 2002


--- 1-27206531-0-90000491 <domi at sun11.ukl.uni-freiburg.de> wrote:
> Dear Prof. Ripley
> 
> Using your advice:
> 
> >library(lattice)
> >library(nlme)
> >data(Orthodont)
> >plot(Orthodont)
> 
> >lset(theme = c("bw"))
> Error in trellis.par.set("background", list(col = bg)) : 
>         Object "bg" not found

Sorry, that's a bug in lset. you can get the equivalent effect by

trellis.device(new = FALSE, col = FALSE, bg = "white")

(if you already have a device open).


> I also do not understand the description of the help file:
> 
> >Usage:
> >
> >    lset(theme = c("col.bg", "white.bg", "bw"), file)
> >
> >Arguments:
> >
> >    file: the name of a file that will be `source()'d.
> 
> which file should be sourced in my case?

Ignore this option, it has been scrapped in the next version. See below.

> Also one sentence in the help file seems strange to me:
> 
> >     `lset' implements a concept of `themes' in Lattice. Themes are
> >     predefined values of `trellis.settings' that modify the overall
> >     look. The only current theme significantly different from the
> >     defaults is the `"white.bg"' theme, which hopefully
> 
> The sentence ends after hopefully and I expect something after hopefully

Sorry, another bug :)


> I feel that the concept of themes is exactly what I need. But I can't
> activate it. I also searching for examples in the help. But I cant find
> one.

As the documentation says, this was a very preliminary implementation of 
themes. The development version (to be released with R 1.5.0) handles 
these things very differently, and hopefully in a much better way. Till 
then, it's probably better not to use lset directly, but rather use 
trellis.device, trellis.par.get and trellis.par.set. In particular, to change
the background to white, you need 

trellis.par.set("background", list(col = "white"))

To change the default plotting symbol and line color, you'll have to change
the "plot.symbol" and "plot.line" components.


> After reading cross help files and with some try and error I found a dirty
> solution for my problem.
> 
> library(nlme)
> library(lattice)
> trellis.device(device="windows", color=F) # sets the output to bw
> data(Orthodont)
> plot(Orthodont)

Why is this a dirty solution ? It looks perfect to me.

> Now I got exactly what I want. But if I want to export the plot to jpeg:
> 
> trellis.device(device="jpeg", color=F)
> if(interactive()) {
>  jpeg("c:/temp/mist.jpg", quality = 100)
>  plot(Orthodont)
>  dev.off()
> }

I'm not sure why this might happen. But why are you calling jpeg() again ?
trellis.device does that itself (with a filename of "Rplot.jpeg" probably, 
unless you specify a filename).

> The Jpeg- file is white without a picture. Then I tried to export it via
> the GUI. This works fine. 
> 
> Now my question. How can I make proper use of "theme"? I'm aware that my
> problem is probably caused by not understanding the principles of making
> figures with Trellis. But perhaps you, ore someone else can clarify my
> confuse thoughts or point me to some examples.

Depends on what you want to do. The standard way of changing settings in 
Trellis is using trellis.par.get and trellis.par.set, look at the help page
for those functions for how to use them. If you want to change many settings,
this can become a bit tedious, as you would have to call these functions many 
times, and it might be a better idea to store the calls in a file and source 
them all at once.

Incidentally, all these problems with light colors are caused by a somewhat
serious bug in trellis.device(), which assigns the background color
incorrectly.
The actual intended defaults can be simulated by 

trellis.device(device=<whatever>, col = TRUE, bg = "#909090")

for color devices and

trellis.device(device=<whatever>, col = FALSE, bg = "white")

for black and white devices.

Hope that helps.


> Thank you for your help,
> 
> Dominik
> --------------------------------------------------------------------------
> Domink Grathwohl; Bussstr. 34; D-79102 Freiburg
> 
> 
> 
> On Wed, 17 Apr 2002 ripley at stats.ox.ac.uk wrote:
> 
> > ?lset
> > ?trellis.settings.
> > 
> > Reminder: Lattice is not Trellis and it is built on grid not S graphics,
> > so you can't mix in ideas from S graphics.
> > 
> > If you want a black-and-white plot, use lset to set the bw theme.
> > 
> > 
> > On Wed, 17 Apr 2002, 1-27206531-0-90000491 wrote:
> > 
> > > Dear R-users,
> > >
> > > I use:
> > >
> > > $platform
> > > [1] "i386-pc-mingw32"
> > > $arch
> > > [1] "x86"
> > > $os
> > > [1] "Win32"
> > > $system
> > > [1] "x86, Win32"
> > > $status
> > > [1] ""
> > > $major
> > > [1] "1"
> > > $minor
> > > [1] "4.1"
> > > $year
> > > [1] "2002"
> > > $month
> > > [1] "01"
> > > $day
> > > [1] "30"
> > > $language
> > > [1] "R"
> > >
> > > I try  to repeat the analysis of Jose Pinheiro and Douglas Bates
> described
> > > in their book: Mixed-Effects Models in S and S-PLUS.
> > >
> > > library(lattice)
> > > library(nlme)
> > > data(Orthodont)
> > > plot(Orthodont)
> > > fm1OrthF.lis <- lmList(distance ~ age, data=Orthodont)
> > > plot(intervals(fm1OrthF.lis))
> > > fm1OrthF <- lme(distance ~ age, data=Orthodont, random= ~ 1| Subject)
> > > plot(augPred(fm1OrthF), aspect="xy", grid=TRUE)
> > >
> > > My question: How can I manipulate the colours of the different plots, say
> > > changing symbols and lines from light-blue to black?
> > > e.g. plot(Orthodont, col="black") changes only symbols to black and I
> have
> > > no idea how to change the lines to black.
> > >
> > > Thanks in advance,
> > >
> > > Dominik
> > >
> > >
> ----------------------------------------------------------------------------
> > > Dominik Grathwohl; Bussstr. 34; D-79102 Freiburg
> > >
> > >
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > > 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
> > >
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> > >
> > 
> > -- 
> > Brian D. Ripley,                  ripley at stats.ox.ac.uk
> > Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
> > University of Oxford,             Tel:  +44 1865 272861 (self)
> > 1 South Parks Road,                     +44 1865 272860 (secr)
> > Oxford OX1 3TG, UK                Fax:  +44 1865 272595
> > 
> >
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> > 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
> >
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> > 
> > 
> 
>
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

__________________________________________________

Yahoo! Games - play chess, backgammon, pool and more

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list