Dear group,

I have recognized a strange behaviour of palette(). I tried to find any explanation but failed so far (or even didnt understood the idea behind - what is most probable).

My original plan was to define a palette, save it in a variable and use it later for an image-plot. One reason why I tried to store the palette in a variable was, because I wanted to change individual values (e.g. the first value to gray).

Interestingly, the palette is not defined correctly in the first run, but in the second run.
Simple example:

>rm(list=ls())
> a <- palette(rainbow(6))
> a
[1] "red" "#FF4C00" "#FF9900" "#FFE500" "#CCFF00" "#80FF00" "#33FF00" "#00FF19" "#00FF66" "#00FFB2" "cyan" "#00B3FF" "#0066FF" "#0019FF" "#3300FF" "#8000FF" "#CC00FF"
[18] "#FF00E6" "#FF0099" "#FF004D"
> a <- palette(rainbow(6))
> a
[1] "red"     "yellow"  "green"   "cyan"    "blue"    "magenta"

###################
Interestingly, this works at the first time
> palette(rainbow(20))     # six color rainbow
> plot(rnorm(20),col=1:20)

as well as
> palette(rainbow(6))
> a <- palette()
> a
[1] "red"     "yellow"  "green"   "cyan"    "blue"    "magenta"

So, it seems to be that first a palette has to be defined (or set as to be used) and then the vector can be assigned to a variable. I dont understand why.

Thank you in advance for your help and explanation.

Daniel

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to