ggsci专为paper配色而生
R语言中的ggsci包提供一系列高品质调色板,配色的素材灵感来自科学期刊,数据可视化库,科幻电影和电视节目中使用的颜色。ggsci中的调色板可用作ggplot2调色。对于所有调色板,相应的调用方法是:scale_color_palname() scale_fill_palname() 简单讲就包括了各个杂志的配色风格,整理成了R包,免去了自行配色时的尴尬审美,比如说里面就包括Lancet, NEJM,JAMA,JCO等顶级杂志的配色风格,发不了顶级Paper, 学学配色也是不错的。
Sys.setlocale('LC_ALL','C')
## [1] "C"
library("ggsci")library("ggplot2")library("gridExtra")data("diamonds")head(diamonds)
## # A tibble: 6 x 10## carat cut color clarity depth table price x y z## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31## 4 0.290 Premium I VS2 62.4 58 334 4.2 4.23 2.63## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
dim(diamonds)
## [1] 53940 10
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()p1
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()p2
自动配色,接触直男配色的烦恼 配色方案为sacle_color_xx杂志名,或者scale_fill_xx杂志名 注意杂志名并不是所有的,而是该包含有的一部分配色内容
p1_npg = p1 + scale_color_npg()p2_npg = p2 + scale_fill_npg()grid.arrange(p1_npg, p2_npg, ncol = 2)##grid组图
p1_nejm = p1 + scale_color_nejm()p2_nejm = p2 + scale_fill_nejm()grid.arrange(p1_nejm, p2_nejm, ncol = 2)
scale_color_lancet() scale_fill_lancet
p1_lancet = p1 + scale_color_lancet()p2_lancet = p2 + scale_fill_lancet()grid.arrange(p1_lancet, p2_lancet, ncol = 2)
scale_color_jama函数 scale_color_jama函数
p1_lancet = p1 + scale_color_lancet()p2_lancet = p2 + scale_fill_lancet()grid.arrange(p1_lancet, p2_lancet, ncol = 2)
首先pal_xx杂志名函数得到颜色代码 然后scales包俩展现函数 做个NEJM配色的展示,可以先问号下?pal_xx函数
nejm<-pal_nejm("default",alpha = 1)(8)##(9表示呈现多少个颜色)nejm
## [1] "#BC3C29FF" "#0072B5FF" "#E18727FF" "#20854EFF" "#7876B1FF" "#6F99ADFF"## [7] "#FFDC91FF" "#EE4C97FF"
scales::show_col(nejm)
可能官方给的图形太复杂,我们来创建一个大家熟悉的图
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.6.1
## ## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':## ## combine
## The following objects are masked from 'package:stats':## ## filter, lag
## The following objects are masked from 'package:base':## ## intersect, setdiff, setequal, union
head(diamonds)
## # A tibble: 6 x 10## carat cut color clarity depth table price x y z## <dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>## 1 0.23 Ideal E SI2 61.5 55 326 3.95 3.98 2.43## 2 0.21 Premium E SI1 59.8 61 326 3.89 3.84 2.31## 3 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31## 4 0.290 Premium I VS2 62.4 58 334 4.2 4.23 2.63## 5 0.31 Good J SI2 63.3 58 335 4.34 4.35 2.75## 6 0.24 Very Good J VVS2 62.8 57 336 3.94 3.96 2.48
p<-diamonds %>% ggplot()+ aes(x=cut,y=price,fill=cut) + geom_boxplot()p
简单快捷,无需动脑,因为填充会比较明显,我们选择填充配色
p+scale_fill_lancet()
p+scale_fill_nejm()
我是老朋友白介素2,这样的配色你值得拥有!
欢迎关注生信人
TCGA | 小工具 | 数据库 |组装| 注释 | 基因家族 | Pvalue
基因预测 |bestorf | sci | NAR | 在线工具 | 生存分析 | 热图
生信不死 | 初学者 | circRNA | 一箭画心| 十二生肖 | circos
舞台|基因组 | 黄金测序 | 套路 | 杂谈组装 | 进化 | 测序简史