sci配色
sunqi
2020/7/19
概述
使用到的包ggsci
ggsci提供了一系列高质量的调色板,其灵感来自于科学期刊、数据可视化图书馆、科幻电影和电视节目中使用的色彩。ggsci中的调色板可以对ggplot2使用,目前支持JAMA、Lancet等杂志的配色
包的安装及使用
代码语言:javascript复制library("ggsci")
library("ggplot2")
library("gridExtra")
library(ggpubr)
data("diamonds")
# 离散数据的绘图
p1 = ggplot(subset(diamonds, carat >= 2.2),
aes(x = table, y = price, colour = cut))
geom_point(alpha = 0.7)
geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1)
theme_bw()
p2 = ggplot(subset(diamonds, carat > 2.2 & depth > 55 & depth < 70),
aes(x = depth, fill = cut))
geom_histogram(colour = "black", binwidth = 1, position = "dodge")
theme_bw()
# Nature Publishing Group主题色
p1_npg = p1 scale_color_npg()
p2_npg = p2 scale_fill_npg()
# A和B是原始配色,C和D为新配色
ggarrange(p1,p2,p1_npg,p2_npg,ncol=2,nrow=2,labels=c("A","B","C","D"))
代码语言:javascript复制# American Association for the Advancement of Science
p1_aaas = p1 scale_color_aaas()
p2_aaas = p2 scale_fill_aaas()
# A和B是原始配色,C和D为新配色
ggarrange(p1,p2,p1_aaas,p2_aaas,ncol=2,nrow=2,labels=c("A","B","C","D"))
代码语言:javascript复制# The New England Journal of Medicine
p1_nejm = p1 scale_color_nejm()
p2_nejm = p2 scale_fill_nejm()
# A和B是原始配色,C和D为新配色
ggarrange(p1,p2,p1_nejm,p2_nejm,ncol=2,nrow=2,labels=c("A","B","C","D"))
代码语言:javascript复制# Rick and Morty 配色,嘿嘿嘿
p1_rickandmorty = p1 scale_color_rickandmorty()
p2_rickandmorty = p2 scale_fill_rickandmorty()
# A和B是原始配色,C和D为Rick and Morty配色
ggarrange(p1,p2,p1_rickandmorty,p2_rickandmorty,ncol=2,nrow=2,labels=c("A","B","C","D"))
ggsci支持的配色方法有很多
Name | Scales | Palette Types | Palette Generator | |
---|---|---|---|---|
NPG | scale_color_npg() scale_fill_npg() | “nrc” | pal_npg() | |
AAAS | scale_color_aaas() scale_fill_aaas() | “default” | pal_aaas() | |
NEJM | scale_color_nejm() scale_fill_nejm() | “default” | pal_nejm() | |
Lancet | scale_color_lancet() scale_fill_lancet() | “lanonc” | pal_lancet() | |
JAMA | scale_color_jama() scale_fill_jama() | “default” | pal_jama() | |
JCO | scale_color_jco() scale_fill_jco() | “default” | pal_jco() | |
UCSCGB | scale_color_ucscgb() scale_fill_ucscgb() | “default” | pal_ucscgb() | |
D3 | scale_color_d3() scale_fill_d3() | “category10” “category20” “category20b” “category20c” | pal_d3() | |
LocusZoom | scale_color_locuszoom() scale_fill_locuszoom() | “default” | pal_locuszoom() | |
IGV | scale_color_igv() scale_fill_igv() | “default” “alternating” | pal_igv() | |
UChicago | scale_color_uchicago() scale_fill_uchicago() | “default” “light” “dark” | pal_uchicago() | |
Star Trek | scale_color_startrek() scale_fill_startrek() | “uniform” | pal_startrek() | |
Tron Legacy | scale_color_tron() scale_fill_tron() | “legacy” pal_tron() | ||
Futurama | scale_color_futurama() scale_fill_futurama() | “planetexpress” | pal_futurama() | |
Rick and Morty | scale_color_rickandmorty() scale_fill_rickandmorty() | “schwifty” | pal_rickandmorty() | |
The Simpsons | scale_color_simpsons() scale_fill_simpsons() | “springfield” | pal_simpsons() | |
GSEA | scale_color_gsea() scale_fill_gsea() | “default” | pal_gsea() | |
Material Design | scale_color_material() scale_fill_material() | “red” “pink” “purple” “deep-purple” “indigo” “blue” “light-blue” “cyan” “teal” “green” “light-green” “lime” “yellow” “amber” “orange” “deep-orange” “brown” “grey” “blue-grey” | pal_material() |
对于连续数据的配色
代码语言:javascript复制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主题
p3_gsea = p3 scale_fill_gsea()
p3_gsea_inv = p3 scale_fill_gsea(reverse = TRUE)
grid.arrange(p3_gsea, p3_gsea_inv, ncol = 2)
结束语
看起来很好,但说实话,没啥大用,玩玩可以。 love&peace