Sharp break in color palette in r
I am creating a color palette with the following code:
library(rgl)
fv.colors = colorRampPalette(c("white","tan4","green"))
colorlut = terrain.colors(100)[c(100,95,90,85,80,75:30,25,20,15,14:1)]
col = colorlut[fv-trnlim[1]+1 ]
which gives this: (the color strip was created following the code provided here)
What I would like to have instead is a strip of white at 0, as I currently have, but then a clean break at 0.01 where the palette would start at "tan4", rather than what it does now, i.e. go gradually from white to "tan4" (actually, at no point does it get as dark as tan4).
Apologies if it'开发者_Python百科s a very simple answer but after many tries and much googling, I still can't work it out.
Thanks!
A small modification of your code seems to provide the answer you are after:
fv.colors = colorRampPalette(c("white","tan4","green")) ## define the color ramp
colorlut = fv.colors(100)[c(1,seq(50,100,length.out=99))] ## select colors to use
plot(0:1,0:1,type='n',xaxs='i',yaxs='i') ## define the plotting area
## illustrate the vector of colors using rectangles
rect(seq(0,0.99,0.01),rep(0,100),seq(0.01,1,0.01),rep(1,100),col = colorlut,border = NA)
box() ## make sure that the graph's frame is not covered up
Edit: The colours are a bit ugly to my eye, but you can adjust this by redefining the color ramp or the selection of colors from the ramp.
精彩评论