Gorjanc Gregor
2004-Oct-17 18:33 UTC
FW: [R] Plotcorr: colour the ellipses to emphasize the differences
-----Original Message----- From: Duncan Murdoch [mailto:murdoch at stats.uwo.ca] Sent: ned 2004-10-17 15:34 To: Gorjanc Gregor Cc: r-help at stat.math.ethz.ch Subject: Re: [R] Plotcorr: colour the ellipses to emphasize the differences On Sun, 17 Oct 2004 02:51:58 +0200, "Gorjanc Gregor" <Gregor.Gorjanc at bfro.uni-lj.si> wrote: [removed old stuff]>>I would also like to know if it is possible to use some other scale of >> colors instead of cm.colors, rainbow, heat.colors, terrain.colors, >> topo.colors. I would like to have positive correlations in blue and >> nagative ones in red spectrum of colors. Is it possible?> The source of cm.colors is visible (just type "cm.colors" and it will > be printed). You could write your own function to change the scale to > blue through red instead of cyan through magenta by changing a few > constants in that function.Thanks, that helped me to do what I wanted. Thanks. Bellow is the code. cm.colors <- function (n) { # from red from=0 # to blue to=8/12 if ((n <- as.integer(n[1])) > 0) { even.n <- n%%2 == 0 k <- n%/%2 l1 <- k + 1 - even.n l2 <- n - k + even.n c(if (l1 > 0) hsv(h = from, s = seq(0.5, ifelse(even.n, 0.5/k, 0), length = l1), v = 1), if (l2 > 1) hsv(h = to, s = seq(0, 0.5, length = l2)[-1], v = 1)) } else character(0) }> 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! With regards, Gregor GORJANC
Duncan Murdoch
2004-Oct-17 20:02 UTC
FW: [R] Plotcorr: colour the ellipses to emphasize the differences
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
Reasonably Related Threads
- Plotcorr: colour the ellipses to emphasize the differences
- Drawing a colour wheel - bug in hcl?
- Selecting complementary colours
- [849] trunk/wxruby2/lib/wx/classes/colour.rb: Stock colours weren''t initializing correctly
- Strategy for creating a palette...?