簡體   English   中英

R中的調色板急劇中斷

[英]Sharp break in color palette in r

我正在使用以下代碼創建調色板:

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 ]

它給出了以下內容:(顏色條是根據此處提供的代碼創建的)

在此處輸入圖片說明

我現在想要的是像現在一樣在0處有一條白色的條帶,然后在0.01處干凈地斷開,調色板將從“ tan4” 開始 ,而不是現在的顏色,即從白色逐漸變為“ tan4”(實際上,它永遠不會變得像tan4一樣暗)。

道歉,如果這是一個非常簡單的答案,但是經過多次嘗試和大量谷歌搜索,我仍然無法解決。

謝謝!

對您的代碼進行少量修改似乎可以為您提供答案:

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

編輯:顏色對我來說有點難看,但是您可以通過重新定義顏色漸變或從漸變中選擇顏色來進行調整。

顏色表示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM