jamesbang

V1

2022/09/19阅读：124主题：雁栖湖

# 🤩 ggsci | 一秒搞定你的顶刊配色（一）

## 2用到的包

``rm(list = ls())library(tidyverse)library(ggsci)library(patchwork)``

## 3示例数据

``library(ggstatsplot)dat <- movies_long``

``str(dat)``

## 4离散型配色

### 4.1 初步绘图

``p1 <-  dat %>%   ggplot(aes(x = length, y = rating, colour = genre)) +  geom_point(alpha = 0.7) +  geom_smooth(method = "loess", alpha = 0.05, size = 1, span = 1) +  theme_bw()p2 <-  dat %>%   ggplot(aes(x = rating, fill = genre)) +  geom_histogram(binwidth = 0.8, position = "dodge") +  theme_bw()p1 + p2``

### 4.2 NPG配色

``p1_npg <-  p1 + scale_color_npg()p2_npg <-  p2 + scale_fill_npg()p1_npg + p2_npg``

### 4.3 AAAS配色

``p1_aaas <-  p1 + scale_color_aaas()p2_aaas <-  p2 + scale_fill_aaas()p1_aaas + p2_aaas``

### 4.4 NEJM配色

``p1_nejm = p1 + scale_color_nejm()p2_nejm = p2 + scale_fill_nejm()p1_nejm + p2_nejm``

### 4.5 Lancet配色

``p1_lancet <-  p1 + scale_color_lancet()p2_lancet <-  p2 + scale_fill_lancet()p1_lancet + p2_lancet``

### 4.6 JAMA配色

``p1_jama <-  p1 + scale_color_jama()p2_jama <-  p2 + scale_fill_jama()p1_jama + p2_jama``

### 4.7 JCO配色

``p1_jco <-  p1 + scale_color_jco()p2_jco <-  p2 + scale_fill_jco()p1_jco + p2_jco``

### 4.8 UCSCGB配色

``p1_ucscgb <-  p1 + scale_color_ucscgb()p2_ucscgb <-  p2 + scale_fill_ucscgb()p1_ucscgb + p2_ucscgb``

### 4.9 D3配色

``p1_d3 <-  p1 + scale_color_d3()p2_d3 <-  p2 + scale_fill_d3()p1_d3 + p2_d3``

### 4.10 LocusZoom配色

``p1_locuszoom <-  p1 + scale_color_locuszoom()p2_locuszoom <-  p2 + scale_fill_locuszoom()p1_locuszoom + p2_locuszoom``

### 4.11 Integrative Genomics Viewer配色

``p1_igv <-  p1 + scale_color_igv()p2_igv <-  p2 + scale_fill_igv()p1_igv + p2_igv``

### 4.12 UChicago配色

``p1_uchicago <-  p1 + scale_color_uchicago()p2_uchicago <-  p2 + scale_fill_uchicago()p1_uchicago + p2_uchicago``

### 4.13 Star Trek配色

``p1_startrek <-  p1 + scale_color_startrek()p2_startrek <-  p2 + scale_fill_startrek()p1_startrek+ p2_startrek``

### 4.14 Tron Legacy配色

``p1_tron <-  p1 + scale_color_tron()p2_tron <-  p2 + scale_fill_tron()p1_tron + p2_tron``

### 4.15 Futurama配色

``p1_futurama <-  p1 + scale_color_futurama()p2_futurama <-  p2 + scale_fill_futurama()p1_futurama + p2_futurama``

### 4.16 Rick and Morty配色

``p1_rickandmorty <-  p1 + scale_color_rickandmorty()p2_rickandmorty <-  p2 + scale_fill_rickandmorty()p1_rickandmorty + p2_rickandmorty``

### 4.17 The Simpsons配色

``p1_simpsons <-  p1 + scale_color_simpsons()p2_simpsons <-  p2 + scale_fill_simpsons()p1_simpsons + p2_simpsons``

## 5连续型配色

### 5.1 初步绘图

``library("reshape2")cor <- cor(unname(cbind(dat[,3:6],dat[,3:6],dat[,3:6],dat[,3:6])))cor_melt <-  melt(cor)                 p3 <-  cor_melt %>%  ggplot(aes(x = Var1, y = Var2, fill = value)) +  geom_tile(size = 0.3,na.rm = T) +  theme_bw() +  theme(axis.title.x = element_blank(),        axis.title.y = element_blank())p3``

### 5.2 GSEA配色

``p3_gsea     <-  p3 + scale_fill_gsea()p3_gsea_inv <-  p3 + scale_fill_gsea(reverse = TRUE)p3_gsea + p3_gsea_inv``

### 5.3 Material Design

``wrap_plots(  p3 + scale_fill_material("red"),         p3 + scale_fill_material("pink"),  p3 + scale_fill_material("purple"),      p3 + scale_fill_material("deep-purple"),  p3 + scale_fill_material("indigo"),      p3 + scale_fill_material("blue"),  p3 + scale_fill_material("light-blue"),  p3 + scale_fill_material("cyan"),  p3 + scale_fill_material("teal"),        p3 + scale_fill_material("green"),  p3 + scale_fill_material("light-green"), p3 + scale_fill_material("lime"),  p3 + scale_fill_material("yellow"),      p3 + scale_fill_material("amber"),  p3 + scale_fill_material("orange"),      p3 + scale_fill_material("deep-orange"),  p3 + scale_fill_material("brown"),       p3 + scale_fill_material("grey"),  p3 + scale_fill_material("blue-grey"))``

## 6非ggplot中的应用

### 6.1 提取配色

``mypal <-  pal_npg("nrc", alpha = 0.7)(9)mypal``

### 6.2 显示配色

``library("scales")show_col(mypal)``

##### jamesbang
V1

wx🔍: Grassssss 卷起来了