Re: [S] colour postscript files

Tony Plate (Tony.Plate@mcs.vuw.ac.nz)
Thu, 21 May 1998 11:17:56 +1200


Here's how I managed to produce color postscript plots, and
a key of the colors available. (Under S-PLUS 3.4 for UNIX)

Read in the function color.view (at the end) first. The first
four of these plots use the built-in color definitions ps.colors.rgb,
which gives 738 colors. Other color schemes are available within
S+ -- search in the documentation.

One thing that tripped me up was that the documentation for
ps.options() says that colors should be specified in the
RGB model. However, it appears that this is wrong, hence
the conversion below to the HSB model.

# ps.colors.rgb 1:369
trellis.device(postscript,file="pscolorA.ps",horizontal=T,colors=ps.rgb2hsb(ps.colors.rgb),onefile=T)
color.view(1:369,column=8,lwd=16,text.color=41)
dev.off()

# ps.colors.rgb 370:738
trellis.device(postscript,file="pscolorB.ps",horizontal=T,colors=ps.rgb2hsb(ps.colors.rgb),onefile=T)
color.view(370:738,column=8,lwd=16,text.color=41)
dev.off()

# ps.colors.rgb 1:369 on black background
trellis.device(postscript,file="pscolorAblk.ps",horizontal=T,colors=ps.rgb2hsb(ps.colors.rgb),onefile=T,background=41)
color.view(1:369,column=8,lwd=16,text.color=1)
dev.off()

# ps.colors.rgb 370:738 on black background
trellis.device(postscript,file="pscolorBblk.ps",horizontal=T,colors=ps.rgb2hsb(ps.colors.rgb),onefile=T,background=41)
color.view(370:738,column=8,lwd=16,text.color=1)
dev.off()

# trellis colors
trellis.device(postscript,file="trelliscolor.ps",horizontal=T,color=T,onefile=T)
color.view(1:200,column=5,lwd=16)
dev.off()

color.view <- function(color.range=2:7,lwd=2,columns=1,text.color=1) {
old.par <- par()
par(mfrow=c(1,1))
ncolor <- length(color.range)+1
plot(0:1, 0:1, type = "n",axes=F,xlab="",ylab="")
par(mar=rep(0,4))
colwidth <- 1/columns
for(i in 1:length(color.range)) {
par(col = color.range[i]);
par(lwd=lwd)
column <- floor(i/ceiling(ncolor/columns))
xpos <- column * colwidth + colwidth/3
ypos <- i/ceiling(ncolor/columns)
ypos <- 1 - (ypos - floor(ypos))
lines(c(xpos+colwidth/10, xpos+colwidth/3-colwidth/10), rep(ypos, 2))
par(col=text.color)
text(format(color.range[i]),x=ifelse(i%%2==0,xpos,xpos+colwidth/3),
y=ypos, adj=ifelse(i%%2==0,1,0))
}
par(old.par)
invisible(NULL)
}

-- Tony Plate

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news