knitr::opts_chunk$set(collapse = TRUE, comment = "#>", fig.width = 7, fig.height = 7, fig.align = "center") library(scales) library(RColorBrewer)
介绍获取色彩的一些途径。
n <- 10 rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha = 1) heat.colors(n, alpha = 1) terrain.colors(n, alpha = 1) topo.colors(n, alpha = 1) cm.colors(n, alpha = 1)
show_col(rainbow(10),labels = T)
oblue <- colorRampPalette(c("orange", "blue")) show_col(oblue(10),labels = T)
n <- 200 temp.col <- oblue(n) par(mar = c(0.5,0.5,2,0.5)) barplot(rep(1,times = n),col = temp.col, border = temp.col, horiz = F, axes = FALSE)
系统本身提供了657种命名色彩,通过colors()函数,可以获取名称。
head(colors(), 12)
绘制所有色彩如下:
show_col(colours(), labels = F)
所有调色板
display.brewer.all(type = "all")
单色系渐变
display.brewer.all(type = "seq")
双色系渐变
display.brewer.all(type = "div")
离散色系
display.brewer.all(type = "qual")
离散颜色
cols <- brewer_pal(palette = "Greens")(5) cols
基于离散颜色,创建连续颜色
cols <- brewer_pal("div")(5) show_col(gradient_n_pal(cols)(seq(0, 1, length.out = 30)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.