[R] background colour

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Jan 14 10:40:11 CET 2008

'bg' is both a graphics parameter and an argument to plot.default: the two 
usages have different meanings.  Please study the help (e.g. ?par, 
?plot.default, ?points) carefully, since you are confusing the two 
meanings in your examples.

On Mon, 14 Jan 2008, Daniel Stepputtis wrote:

> Dear list,
> I am using R 2.6 on a Windows XP machine.
> I divided my device window and tried to set the backgroundcolor for each plot region/figure region separately. This seems not possible?? A simple example:
> # create random numbers
> a <- rnorm(100)
> # divide device window
> par(mfrow=c(1,2))
> # set the backgroundcolour to "red"
> # this always affect the total device

Yes, as documented.

> par(bg="red")
> #two plots should be plotted
> plot(a)
> hist(a)
> I have tried to call "bg" within the high-level-graphic function (plot(bg="red")). Whereas there was no error-message, this has no effect on the background of this singe plot.
> I found a meaningfull answer I have found here: 
> http://finzi.psych.upenn.edu/R/Rhelp02a/archive/21384.html but I was 
> wondering, whether there is a more easy and explicit way to do it 
> directly for a given plot in a multiplot environment. Are there 
> possibilities to do it specifically for the complete figure region or 
> solely for the complete plot region?

Yes, but this would be part of the figure whereas what par(bg=) does is 
not.  So it's down to you to colour the box you want, most easily with 
rect() as Marc showed in the post you cite.

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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list