FW: [R] Plotcorr: colour the ellipses to emphasize the differences
Duncan Murdoch
murdoch at stats.uwo.ca
Sun Oct 17 22:02:08 CEST 2004
On Sun, 17 Oct 2004 20:33:48 +0200, "Gorjanc Gregor"
<Gregor.Gorjanc at bfro.uni-lj.si> wrote:
>-----Original Message-----
>From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca]
>> I think it would be useful to have a general function that did what
>> cm.colors does but for other paths through colour space, but I've
>> never written one (or done a thorough search to see if someone else
>> has.)
>
>I agree with this!
I've now written a little one:
path.colors <- function(n, path=c('cyan', 'white', 'magenta'),
interp=c('rgb','hsv')) {
interp <- match.arg(interp)
path <- col2rgb(path)
nin <- ncol(path)
if (interp == 'hsv') {
path <- rgb2hsv(path)
# Modify the interpolation so that the circular nature of hue
is used
for (i in 2:nin)
path[1,i] <- path[1,i] + round(path[1,i-1]-path[1,i])
result <- apply(path, 1, function(x) approx(seq(0, 1,
len=nin), x, seq(0, 1, len=n))$y)
return(hsv(result[,1] %% 1, result[,2], result[,3]))
} else {
result <- apply(path, 1, function(x) approx(seq(0, 1,
len=nin), x, seq(0, 1, len=n))$y)
return(rgb(result[,1]/255, result[,2]/255, result[,3]/255))
}
}
I'm not entirely happy with it, but you're welcome to play with it.
The general idea is that you give a sequence of colors in either rgb
or hsv space, and it expands that sequence to a longer string of
interpolated colors. For example, the default
path.colors(n, path=c("cyan", "white", "magenta"), interp="rgb")
is fairly close to cm.colors(n) (but more saturated), and
path.colors(n, c("red","green", "blue","red"), interp="hsv")
is like rainbow(n-1) (but it repeats red at the end).
Duncan Murdoch
More information about the R-help
mailing list