R语言内置颜色色板+生成代码

R语言内置颜色参照色板


日常使用中, 想用一些R语言内置颜色, 网上始终没有找到相对齐全的内置色板, 于是自己写了一个.

R语言内置颜色总共657种, 文中代码共生成560种颜色, 去掉了部分Grey渐变色.
代码如下:

// RColors-568
col <- 8
ids <- c(1:263, 361:657)
line <- ceiling(length(ids)/col)
cls <- colors()[ids]
filename <- "RColors.png"
png(filename, width = 1600, height = 3200, units = "px")
par(mar=c(0,0,0,0))
plot(0, 0, type = "n", xlim = c(0, 1), ylim = c(0, 1), axes = FALSE, xlab = "", ylab = "")
rect(rep((0:(col - 1)/col),line), sort(rep((0:(line - 1)/line),col),decreasing=T), rep((1:col/col),line),
     sort(rep((1:line/line),col),decreasing=T), border = "grey80", col=cls[seq(1,line*col)])
text(rep((0:(col - 1)/col),line)+0.062, col = "grey20",
     sort(rep((0:(line - 1)/line),col), decreasing=T)+0.007, paste0(ids,"-",cls)[seq(1,line*col)], cex=1.5)
dev.off()
print(paste0("Saved to ", getwd(), "/", filename))

生成的色板图片:

你可能感兴趣的:(R)