2017-08-01 68 views
1

我想展開一個定性調色板的顏色以獲得更多信息的柵格圖。展開柵格圖的定性調色板R

我一直在使用rasterVis包和特別情節我需要比Paired調色板更多的顏色。

levelplot(..., 
     par.settings = rasterTheme(region = brewer.pal(10,'Paired')), 
     at=seq(0,5000,500), 
     ...) 

通過這個配置,我得到一個光柵從0到5000增加200個單位。 rasterTheme函數讓我根據Paired調色板使用10個不連續的顏色作爲繪圖。

Paired調色板只有12種顏色,如果我想要25種顏色(光柵從0到5000增加200個單位),我必須使用預定義的調色板,這意味着使用順序調色板。

levelplot(..., 
     par.settings = YlOrRdTheme, 
     at=seq(0,5000,200), 
     ...) 

我怎麼能使用25種不同顏色的非連續調色板?我應該手動創建一個調色板還是有一個函數來創建隨機調色板?

謝謝!

回答

0

randomcoloR有兩個函數用於創建具有自變量的隨機顏色,用於選擇所需顏色的數量。使用distinctColorPalette功能的示例:

# load the library 
library(randomcoloR) 

# define the number of colors 
k <- 25 

# generate the colors 
colors <- distinctColorPalette(k = k) 

# proof - plot the colors 
xleft <- seq(1,k,1) 
xright <- xleft+1 
ybottom <- rep(0,k) 
ytop <- ybottom+1 
plot(1, 1, xlim = c(0, k), type = "n", axes = FALSE, bty = "n", xlab = "", 
    ylab = "") 
rect(xleft = xleft, ybottom = ybottom, xright = xright, ytop = ytop, col = 
    colors, border = "white")