My eyes were finally opened and I understood nature.
I learned at the same time to love it.
— Claude Monet
ggsci
offers a collection of high-quality color palettes inspired by colors used in scientific journals, data visualization libraries, and science fiction TV shows. The color palettes in ggsci
are available as ggplot2
scales. For all the color palettes, the corresponding scales are named as:
scale_color_palname()
scale_fill_palname()
We also provided aliases, such as scale_colour_palname()
for scale_color_palname()
. All available color palettes are summarized in the table below.
Name | Scales | Palette Types | Palette Generator |
---|---|---|---|
NPG |
|
|
|
AAAS |
|
|
|
Lancet |
|
|
|
JCO |
|
|
|
UCSCGB |
|
|
|
D3 |
|
|
|
UChicago |
|
|
|
The Simpsons |
|
|
|
Futurama |
|
|
|
Rick and Morty |
|
|
|
GSEA |
|
|
|
We will use scatterplots with smooth curves, and bar plots to demonstrate the discrete color palettes in ggsci
.
library("ggsci")
library("ggplot2")
library("gridExtra")
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()
The NPG palette is inspired by the plots in journals published by Nature Publishing Group:
p1_npg = p1 + scale_color_npg()
p2_npg = p2 + scale_fill_npg()
grid.arrange(p1_npg, p2_npg, ncol = 2)
The AAAS palette is inspired by the plots in journals published by American Association for the Advancement of Science:
p1_aaas = p1 + scale_color_aaas()
p2_aaas = p2 + scale_fill_aaas()
grid.arrange(p1_aaas, p2_aaas, ncol = 2)
The Lancet palette is inspired by the plots in Lancet journals, such as
p1_lancet = p1 + scale_color_lancet()
p2_lancet = p2 + scale_fill_lancet()
grid.arrange(p1_lancet, p2_lancet, ncol = 2)
The JCO palette is inspired by the the plots in
p1_jco = p1 + scale_color_jco()
p2_jco = p2 + scale_fill_jco()
grid.arrange(p1_jco, p2_jco, ncol = 2)
The UCSCGB palette is from the colors used by UCSC Genome Browser for representing chromosomes. This palette has been intensively used in visualizations produced by Circos.
p1_ucscgb = p1 + scale_color_ucscgb()
p2_ucscgb = p2 + scale_fill_ucscgb()
grid.arrange(p1_ucscgb, p2_ucscgb, ncol = 2)
The D3 palette is from the categorical colors used by D3.js (version 3.x and before). There are four palette types (category10
, category20
, category20b
, category20c
) available.
p1_d3 = p1 + scale_color_d3()
p2_d3 = p2 + scale_fill_d3()
p1_d3_c10 = p1 + scale_color_d3("category10")
p2_d3_c10 = p2 + scale_fill_d3("category10")
p1_d3_c20 = p1 + scale_color_d3("category20")
p2_d3_c20 = p2 + scale_fill_d3("category20")
p1_d3_c20b = p1 + scale_color_d3("category20b")
p2_d3_c20b = p2 + scale_fill_d3("category20b")
p1_d3_c20c = p1 + scale_color_d3("category20c")
p2_d3_c20c = p2 + scale_fill_d3("category20c")
grid.arrange(p1_d3_c10, p2_d3_c10,
p1_d3_c20, p2_d3_c20,
p1_d3_c20b, p2_d3_c20b,
p1_d3_c20c, p2_d3_c20c,
ncol = 2, nrow = 4)
The UChicago palette is based on the colors used by The University of Chicago. There are three palette types (default
, light
, dark
) available.
p1_uchicago = p1 + scale_color_uchicago()
p2_uchicago = p2 + scale_fill_uchicago()
p1_uchicago_light = p1 + scale_color_uchicago("light")
p2_uchicago_light = p2 + scale_fill_uchicago("light")
p1_uchicago_dark = p1 + scale_color_uchicago("dark")
p2_uchicago_dark = p2 + scale_fill_uchicago("dark")
grid.arrange(p1_uchicago, p2_uchicago,
p1_uchicago_light, p2_uchicago_light,
p1_uchicago_dark, p2_uchicago_dark,
ncol = 2, nrow = 3)
This palette is inspired by the colors used in the TV show
p1_simpsons = p1 + scale_color_simpsons()
p2_simpsons = p2 + scale_fill_simpsons()
grid.arrange(p1_simpsons, p2_simpsons, ncol = 2)
This palette is inspired by the colors used in the TV show
p1_futurama = p1 + scale_color_futurama()
p2_futurama = p2 + scale_fill_futurama()
grid.arrange(p1_futurama, p2_futurama, ncol = 2)
This palette is inspired by the colors used in the TV show
p1_rickandmorty = p1 + scale_color_rickandmorty()
p2_rickandmorty = p2 + scale_fill_rickandmorty()
grid.arrange(p1_rickandmorty, p2_rickandmorty, ncol = 2)
We will use a correlation matrix visualization (a special type of heatmap) to demonstrate the continuous color palettes in ggsci
.
library("reshape2")
data("mtcars")
cor = cor(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()
The GSEA palette (continuous) is inspired by the heatmaps generated by GSEA GenePattern.
p3_gsea = p3 + scale_fill_gsea()
p3_gsea
To apply the color palettes in ggsci
to other graphics systems (such as base graphics and lattice graphics), simply use the palette generator functions in the table above. For example:
mypal = pal_npg("nrc", alpha = 0.7)(9)
mypal
## [1] "#E64B35B2" "#4DBBD5B2" "#00A087B2" "#3C5488B2" "#F39B7FB2" "#8491B4B2"
## [7] "#91D1C2B2" "#DC0000B2" "#7E6148B2"
library("scales")
show_col(mypal)
You will be able to use the generated hex color codes for such graphics systems accordingly. The transparent level of the entire palette is easily adjustable via the argument "alpha"
in every generator or scale function.
Please note some of the palettes might not be the best choice for certain purposes, such as color-blind safe, photocopy safe, or print friendly. If you do have such considerations, you might want to check out color palettes like ColorBrewer and viridis.
The color palettes in this package are solely created for research purposes. The authors are not responsible for the usage of such palettes.
Project website: ggsci.net