virids调色板
安装和加载,及测试代码
install.packages("viridis")
library(viridis)
library(ggplot2)
ggplot(data.frame(x = rnorm(10000), y = rnorm(10000)), aes(x = x, y = y)) +
geom_hex() + coord_fixed() +
scale_fill_viridis() + theme_bw()
热图调色
seed(1234)
matrix <- matrix(rnorm(100), 20, 10)
matrix[1:10, seq(1, 10, 2)] <- matrix[1:10, seq(1, 10, 2)] + 3
matrix[11:20, seq(2, 10, 2)] <- matrix[11:20, seq(2, 10, 2)] + 2
matrix[15:20, seq(2, 10, 2)] <- matrix[15:20, seq(2, 10, 2)] + 4
colnames(matrix) <- paste("Test", 1:10, sep = "")
rownames(matrix) <- paste("Gene", 1:20, sep = "")
# default
pheatmap(matrix)
# viridis
pheatmap(test, color = viridis(7))
viridis提供的配色方案
RColorBrewer
col = RColorBrewer::brewer.pal(name = "Blues", n = 9)
col
[1] "#F7FBFF" "#DEEBF7" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6" "#2171B5"
[8] "#08519C" "#08306B"
setNames(RColorBrewer::brewer.pal(name = "Blues", n = 7), c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
"#EFF3FF" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6" "#2171B5" "#084594"
也可以用list
代替vector
,
setNames(RColorBrewer::brewer.pal(name = "Blues", n = 7), list("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))