Colorful Plots in S-PLUS and R

In R

Someone claimed they had trouble. I didn't.

oak$ R --vanilla --quiet
> hist(rnorm(1000), freq=FALSE)
> usr <- par("usr")
> curve(dnorm(x), usr[1], usr[2], col=2, add=TRUE)
> dev.copy2eps(file="foo.ps", width=5)
X11 
  2 
> q()
oak$ lpr -P mpls_color foo.ps

The following also worked.

oak$ R --vanilla --quiet
> postscript(file="foo.ps", width=5, height=4, horizontal=FALSE,
+ onefile=FALSE, paper="special")
> hist(rnorm(1000), freq=FALSE)
> usr <- par("usr")
> curve(dnorm(x), usr[1], usr[2], col=2, add=TRUE)
> q()
oak$ ghostview foo.ps
oak$ lpr -P mpls_color foo.ps

In S-PLUS

S-PLUS is a bit trickier (user-hostile might be a more apt description). The problem is that the so-called user-friendly plot devices don't do the right thing with colors. They make nice colors on the monitor, but the colors they use in the PostScript they write are determined by the value of

ps.options("colors")
before the plot device is started! It ignores all your happy mousing around and menu selecting to choose pretty colors.

This works

oak$ Splus
License Warning : S-PLUS license expires Wed Feb 28 23:59:59 2001
S-PLUS : Copyright (c) 1988, 1999 MathSoft, Inc.
S : Copyright Lucent Technologies, Inc.
Version 5.1 Release 1 for Linux 2.0.31 : 1999 
Working data will be in /HOME/faculty/charlie/MySwork 
> foo <- ps.colors.rgb[c("black", "red", "orange", "yellow", "green", "cyan",
+ "blue", "magenta"), ]
> ps.options(colors=foo)
> barplot(rep(1, nrow(foo) - 1), names=dimnames(foo)[[1]][-1], col=2:nrow(foo))
> ps.out.0002.ps

> q()
oak$ lpr -P mpls_color ps.out.0002.ps 
Not shown, of course, is the mousing around. On the options thingy, I changed the print command to echo before I clicked on the "print" button. Note well.

If you don't understand this, blame S-PLUS and the whole notion of user-friendliness. It's not my fault. Enough grovelling in the S-PLUS documentation may make it comprehensible.


Author: Charles Geyer (charlie@stat.umn.edu). Comments or corrections gratefully accepted.