R-beta: Plotting: numeric 'col' colors; col=0, col=1, .. | Nice "funclet"

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 14 15:07:19 CEST 1997


``We all know''
 that R has more flexible and nicer color specifications than S-plus.

There are situations however, where I'd like to specify colors numerically,
e.g.
	1) convenience of using different colors in a for(.) loop
 or
	2) backward compatibility with S.

In S, there's the quite known  ``standard''

	col = 0  :<==>   current background color	[ = white by default]
	col = 1  :<==>   current foreground color, ie. default color. [ = black]

In R, this is currently different:

col = 0 is the same as  col = 2  
	which maybe rather an accident than anything else.
col = 1 however takes a different color than the current foreground
	-- which can be NICE  in certain situations, where we'd rather have
	   points / lines  in a different color than the default foreground
	On the other hand, I think  "S compatibility" is more important here.

I assume that it's not too hard to change the 
``numeric color'' map such as to get S compatibility.

--------------------------------------------

Related issue:

colors() gives a character vector of length 657 with  possible color names.

Quite nice; However, 

 1) how can I find out which of these correspond to col = 2.., K ?

 2) Wouldn't it be nice if this map was mutable ?

--------------------------------------------------------

Here is something, some of you might appreciate for getting an
overview  of 'pch' and numeric col :

###------- numeric 'col' / 'pch'  test -----------
###---------------  ===     ===   ----------------
##
p.pch.col <- function(c.max = 49, codes = 0:c.max,
		      init = if(.Device == "X11") par(bg='gray75'))
{
  ## Purpose: Test / Examine  the  numerical  'pch' & 'col' plotting attributes
  ## -------------------------------------------------------------------------
  ## Arguments: codes: integer codes for  pch & col
  ## -------------------------------------------------------------------------
  ## Author: Martin Maechler, Date: 14 Jul 97, 11:44

  ix <- codes %/% 10
  iy <- 10 - codes  %% 10
  if(!exists(".Device") || is.null(.Device)) x11(height=9)
  init
  plot(ix, iy, type='n', xlim = range(ix) + .15*c(-1,1),
       yaxt = 'n',
       xlab = 'floor( i / 10 )', ylab = ' i  MOD 10',
       main = "points(...., pch = i, col = i, bg = i-10)")
  axis(2, at = 10- 0:9, labels = 9:0)
  for(j in seq(codes)) {
    i <- codes[j]
    points(ix[j]-.1,iy[j],     pch=i, col=i, bg = i-10)
    points(ix[j]+.1,iy[j]-.15, pch=i, col='black', cex = 3)
    text  (ix[j]   ,iy[j]+.15, i)
  }
}
## x11() or
postscript("pch-col-test.ps", landscape= F)
p.pch.col()
p.pch.col(99)


Martin Maechler <maechler at stat.math.ethz.ch>		 <><
Seminar fuer Statistik, SOL G1
ETH (Federal Inst. Technology)	8092 Zurich	 SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1086
http://www.stat.math.ethz.ch/~maechler/
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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