2014-01-29 85 views
0

是否有可能創建大號不同種類的「紅」色。爲了更好地理解,我期待跟隨,但不是灰色,我希望有「紅色」或「紅黑色」。寬範圍的相同顏色在R

mypalette <- rev(grey.colors(10000, start = 0.1, end = 0.5, gamma = 4)) 
plot(1:length(mypalette),1:length(mypalette), col=mypalette, pch=16) 

顏色的包,我知道有有限的顏色範圍。任何想法將不勝感激。

+1

'''plot.'包的'color.gradient(c(1,1),c(1,0),c(0,0),nslices = 10)' – Zbynek

回答

1

如果我明白你想要的,試試colorRampPalette。它會返回一個函數,用於輸出您指定的兩個顏色之間所請求的顏色數量。

reds <- colorRampPalette(c("black","red")) 
reds(5) 
[1] "#000000" "#3F0000" "#7F0000" "#BF0000" "#FF0000" 
+0

這就是我想要的!非常感謝。 –

0

這裏有一些ggplot替代

library(ggplot2) 
df <- data.frame(x = rnorm(100), y = rnorm(100), z = rnorm(100), z2 = factor(1:5)) 

# colour set by continuous variable 
ggplot(data = df, aes(x = x, y = y, colour = z)) + 
    geom_point() + 
    scale_colour_gradient(low = "red", high = "white") 

enter image description here

library(RColorBrewer) 
ggplot(data = df, aes(x = x, y = y, colour = z)) + 
    geom_point() + 
    scale_colour_gradientn(colours = brewer.pal(5, "Reds")) 

enter image description here

# colour set by discrete variable 
ggplot(data = df, aes(x = x, y = y, colour = z2)) + 
    geom_point() + 
    scale_colour_brewer(palette = "Reds") 

enter image description here