辛普森(The Simpsons)
p1_simpsons <- p1 + scale_color_simpsons() p2_simpsons <- p2 + scale_fill_simpsons() grid.arrange(p1_simpsons, p2_simpsons, ncol = 2)
连续型调色板
用相关性热图来展示。
library("reshape2") data("mtcars") #示例数据 cor <- cor(unname(cbind(mtcars, mtcars, mtcars, mtcars))) cor_melt <- melt(cor) p3 <- ggplot( cor_melt, aes(x = Var1, y = Var2, fill = value) ) + geom_tile(colour = "black", size = 0.3) + theme_bw() + theme( axis.title.x = element_blank(), axis.title.y = element_blank() )
GSEA
GSEA调色板的灵感来自GSEA GenePattern生成的热图。
p3_gsea <- p3 + scale_fill_gsea() p3_gsea_inv <- p3 + scale_fill_gsea(reverse = TRUE) grid.arrange(p3_gsea, p3_gsea_inv, ncol = 2)
Material Design
The Material Design color palettes are from the material design color guidelines.
先生成一个随机矩阵
library("reshape2") set.seed(42) k <- 9 x <- diag(k) x[upper.tri(x)] <- runif(sum(1:(k - 1)), 0, 1) x_melt <- melt(x) p4 <- ggplot(x_melt, aes(x = Var1, y = Var2, fill = value)) + geom_tile(colour = "black", size = 0.3) + scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) + theme_bw() + theme( legend.position = "none", plot.background = element_blank(), axis.line = element_blank(), axis.ticks = element_blank(), axis.text.x = element_blank(), axis.text.y = element_blank(), axis.title.x = element_blank(), axis.title.y = element_blank(), panel.background = element_blank(), panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank() )
用19种Material Design调色板绘制矩阵:
grid.arrange( p4 + scale_fill_material("red"), p4 + scale_fill_material("pink"), p4 + scale_fill_material("purple"), p4 + scale_fill_material("deep-purple"), p4 + scale_fill_material("indigo"), p4 + scale_fill_material("blue"), p4 + scale_fill_material("light-blue"), p4 + scale_fill_material("cyan"), p4 + scale_fill_material("teal"), p4 + scale_fill_material("green"), p4 + scale_fill_material("light-green"), p4 + scale_fill_material("lime"), p4 + scale_fill_material("yellow"), p4 + scale_fill_material("amber"), p4 + scale_fill_material("orange"), p4 + scale_fill_material("deep-orange"), p4 + scale_fill_material("brown"), p4 + scale_fill_material("grey"), p4 + scale_fill_material("blue-grey"), ncol = 6 )
非ggplot图
如果不是··作的图,可以直接调用颜色参数。
mypal <- pal_npg("nrc", alpha = 0.7)(9) mypal
library("scales") show_col(mypal)
总结
下表总结了所有可用的调色板。