ggsci/ 0000755 0001762 0000144 00000000000 13276211255 011352 5 ustar ligges users ggsci/TODO 0000644 0001762 0000144 00000001361 13221611720 012032 0 ustar ligges users # TODO
- Okabe, Masataka and Kei Ito's Color Universal Design (CUD) for color blindness: http://jfly.iam.u-tokyo.ac.jp/color/ https://www.chronicle.com/blogs/profhacker/color-blind-accessible-figures/59189 https://www.nature.com/articles/nmeth.1618
- Marvel's The Defenders (colors from opening titles). Red - Daredevil; Blue - Jessica Jones; Orange - Luke Cage; Green - Iron Fist.
- Gephi: https://github.com/gephi/gephi/blob/master/modules/Utils/src/main/java/org/gephi/utils/PaletteUtils.java#L83-L110
- Apple Human Interface Guidelines: https://developer.apple.com/ios/human-interface-guidelines/visual-design/color/ one discrete, one continuous.
- Add a function for displaying all color palettes
- Color palette extraction: http://colormind.io/
ggsci/inst/ 0000755 0001762 0000144 00000000000 13276174761 012341 5 ustar ligges users ggsci/inst/doc/ 0000755 0001762 0000144 00000000000 13276174761 013106 5 ustar ligges users ggsci/inst/doc/ggsci.html 0000644 0001762 0000144 00017257715 13276174761 015121 0 ustar ligges users
Scientific Journal and Sci-Fi Themed Color Palettes for ggplot2
Scientific Journal and Sci-Fi Themed
Color Palettes for ggplot2
2018-05-13
Introduction
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, science fiction movies, and 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.
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() |
Discrete Color Palettes
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()
NPG
The NPG palette is inspired by the plots in the journals published by Nature Publishing Group:

AAAS
The AAAS palette is inspired by the plots in the journals published by American Association for the Advancement of Science:

NEJM
The NEJM palette is inspired by the plots in The New England Journal of Medicine:

Lancet
The Lancet palette is inspired by the plots in Lancet journals, such as Lancet Oncology:

JAMA
The JAMA palette is inspired by the plots in The Journal of the American Medical Association:

JCO
The JCO palette is inspired by the the plots in Journal of Clinical Oncology:

UCSCGB
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.

D3
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.

LocusZoom
The LocusZoom palette is based on the colors used by LocusZoom.

IGV
The IGV palette is from the colors used by Integrative Genomics Viewer for representing chromosomes. There are two palette types (default
, alternating
) available.

UChicago
The UChicago palette is based on the colors used by the University of Chicago. There are three palette types (default
, light
, dark
) available.

Star Trek
This palette is inspired by the (uniform) colors in Star Trek:

Tron Legacy
This palette is inspired by the colors used in Tron Legacy. It is suitable for displaying data when using a dark theme:

Futurama
This palette is inspired by the colors used in the TV show Futurama:

Rick and Morty
This palette is inspired by the colors used in the TV show Rick and Morty:

The Simpsons
This palette is inspired by the colors used in the TV show The Simpsons:

Continuous Color Palettes
We will use a correlation matrix visualization (a special type of heatmap) to demonstrate the continuous color palettes in ggsci
.
GSEA
The GSEA palette (continuous) is inspired by the heatmaps generated by GSEA GenePattern.

Material Design
The Material Design color palettes are from the material design color guidelines.
We generate a random matrix first:
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())
Plot the matrix with the 19 material design color palettes:
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)

From the figure above, we can see that even though an identical matrix was visualized by all plots, some palettes are more preferrable than the others because our eyes are more sensitive to the changes of their saturation levels.
Non-ggplot2 Graphics
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:
## [1] "#E64B35B2" "#4DBBD5B2" "#00A087B2" "#3C5488B2" "#F39B7FB2" "#8491B4B2"
## [7] "#91D1C2B2" "#DC0000B2" "#7E6148B2"

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.
Discussion
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.
ggsci/inst/doc/ggsci.R 0000644 0001762 0000144 00000015011 13276174760 014322 0 ustar ligges users ## ------------------------------------------------------------------------
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()
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_npg = p1 + scale_color_npg()
p2_npg = p2 + scale_fill_npg()
grid.arrange(p1_npg, p2_npg, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_aaas = p1 + scale_color_aaas()
p2_aaas = p2 + scale_fill_aaas()
grid.arrange(p1_aaas, p2_aaas, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_nejm = p1 + scale_color_nejm()
p2_nejm = p2 + scale_fill_nejm()
grid.arrange(p1_nejm, p2_nejm, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_lancet = p1 + scale_color_lancet()
p2_lancet = p2 + scale_fill_lancet()
grid.arrange(p1_lancet, p2_lancet, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_jama = p1 + scale_color_jama()
p2_jama = p2 + scale_fill_jama()
grid.arrange(p1_jama, p2_jama, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_jco = p1 + scale_color_jco()
p2_jco = p2 + scale_fill_jco()
grid.arrange(p1_jco, p2_jco, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_ucscgb = p1 + scale_color_ucscgb()
p2_ucscgb = p2 + scale_fill_ucscgb()
grid.arrange(p1_ucscgb, p2_ucscgb, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_d3 = p1 + scale_color_d3()
p2_d3 = p2 + scale_fill_d3()
grid.arrange(p1_d3, p2_d3, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_locuszoom = p1 + scale_color_locuszoom()
p2_locuszoom = p2 + scale_fill_locuszoom()
grid.arrange(p1_locuszoom, p2_locuszoom, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_igv_default = p1 + scale_color_igv()
p2_igv_default = p2 + scale_fill_igv()
grid.arrange(p1_igv_default, p2_igv_default, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_uchicago = p1 + scale_color_uchicago()
p2_uchicago = p2 + scale_fill_uchicago()
grid.arrange(p1_uchicago, p2_uchicago, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_startrek = p1 + scale_color_startrek()
p2_startrek = p2 + scale_fill_startrek()
grid.arrange(p1_startrek, p2_startrek, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_tron = p1 + theme_dark() + theme(
panel.background = element_rect(fill = "#2D2D2D"),
legend.key = element_rect(fill = "#2D2D2D")) +
scale_color_tron()
p2_tron = p2 + theme_dark() + theme(
panel.background = element_rect(fill = "#2D2D2D")) +
scale_fill_tron()
grid.arrange(p1_tron, p2_tron, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_futurama = p1 + scale_color_futurama()
p2_futurama = p2 + scale_fill_futurama()
grid.arrange(p1_futurama, p2_futurama, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p1_rickandmorty = p1 + scale_color_rickandmorty()
p2_rickandmorty = p2 + scale_fill_rickandmorty()
grid.arrange(p1_rickandmorty, p2_rickandmorty, ncol = 2)
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
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())
## ---- fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150----
p3_gsea = p3 + scale_fill_gsea()
p3_gsea_inv = p3 + scale_fill_gsea(reverse = TRUE)
grid.arrange(p3_gsea, p3_gsea_inv, ncol = 2)
## ------------------------------------------------------------------------
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())
## ---- fig.width = 10.67, fig.height = 7.12, out.width = 800, out.height = 533, dpi = 150----
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)
## ---- fig.width = 6.67, fig.height = 6.67, out.width = 500, out.height = 500, dpi = 150----
mypal = pal_npg("nrc", alpha = 0.7)(9)
mypal
library("scales")
show_col(mypal)
ggsci/inst/doc/ggsci.Rmd 0000644 0001762 0000144 00000045114 13276174703 014647 0 ustar ligges users ---
title: "Scientific Journal and Sci-Fi Themed
Color Palettes for ggplot2"
author: "Nan Xiao <>
Miaozhu Li <>"
date: "`r Sys.Date()`"
output:
rmarkdown::html_vignette:
toc: true
number_sections: true
css: ggsci.css
vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteIndexEntry{Scientific Journal and Sci-Fi Themed Color Palettes for ggplot2}
---
# Introduction
> 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,
science fiction movies, and 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 | `scale_color_npg()` | `"nrc"` | `pal_npg()` |
| | `scale_fill_npg()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| AAAS | `scale_color_aaas()` | `"default"` | `pal_aaas()` |
| | `scale_fill_aaas()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| NEJM | `scale_color_nejm()` | `"default"` | `pal_nejm()` |
| | `scale_fill_nejm()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Lancet | `scale_color_lancet()` | `"lanonc"` | `pal_lancet()` |
| | `scale_fill_lancet()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| JAMA | `scale_color_jama()` | `"default"` | `pal_jama()` |
| | `scale_fill_jama()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| JCO | `scale_color_jco()` | `"default"` | `pal_jco()` |
| | `scale_fill_jco()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| UCSCGB | `scale_color_ucscgb()` | `"default"` | `pal_ucscgb()` |
| | `scale_fill_ucscgb()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| D3 | `scale_color_d3()`
| `"category10"` | `pal_d3()` |
| | `scale_fill_d3()` | `"category20"` | |
| | | `"category20b"` | |
| | | `"category20c"` | |
+-----------------+------------------------------+--------------------------------+----------------------+
| LocusZoom | `scale_color_locuszoom()` | `"default"` | `pal_locuszoom()` |
| | `scale_fill_locuszoom()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| IGV | `scale_color_igv()` | `"default"`
| `pal_igv()` |
| | `scale_fill_igv()` | `"alternating"` | |
+-----------------+------------------------------+--------------------------------+----------------------+
| UChicago | `scale_color_uchicago()` | `"default"`
| `pal_uchicago()` |
| | `scale_fill_uchicago()` | `"light"`
| |
| | | `"dark"` | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Star Trek | `scale_color_startrek()` | `"uniform"` | `pal_startrek()` |
| | `scale_fill_startrek()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Tron Legacy | `scale_color_tron()` | `"legacy"` | `pal_tron()` |
| | `scale_fill_tron()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Futurama | `scale_color_futurama()` | `"planetexpress"` | `pal_futurama()` |
| | `scale_fill_futurama()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Rick and Morty | `scale_color_rickandmorty()` | `"schwifty"` | `pal_rickandmorty()` |
| | `scale_fill_rickandmorty()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| The Simpsons | `scale_color_simpsons()` | `"springfield"` | `pal_simpsons()` |
| | `scale_fill_simpsons()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| GSEA | `scale_color_gsea()` | `"default"` | `pal_gsea()` |
| | `scale_fill_gsea()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| Material Design | `scale_color_material()` | `"red"` `"pink"`
| `pal_material()` |
| | `scale_fill_material()` | `"purple"` `"deep-purple"`
| |
| | | `"indigo"` `"blue"`
| |
| | | `"light-blue"` `"cyan"`
| |
| | | `"teal"` `"green"`
| |
| | | `"light-green"` `"lime"`
| |
| | | `"yellow"` `"amber"`
| |
| | | `"orange"` `"deep-orange"`
| |
| | | `"brown"` `"grey"`
| |
| | | `"blue-grey"` | |
+-----------------+------------------------------+--------------------------------+----------------------+
# Discrete Color Palettes
We will use scatterplots with smooth curves, and bar plots to demonstrate
the discrete color palettes in `ggsci`.
```{r}
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()
```
## NPG
The NPG palette is inspired by the plots in the journals published by
Nature Publishing Group:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_npg = p1 + scale_color_npg()
p2_npg = p2 + scale_fill_npg()
grid.arrange(p1_npg, p2_npg, ncol = 2)
```
## AAAS
The AAAS palette is inspired by the plots in the journals published by
American Association for the Advancement of Science:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_aaas = p1 + scale_color_aaas()
p2_aaas = p2 + scale_fill_aaas()
grid.arrange(p1_aaas, p2_aaas, ncol = 2)
```
## NEJM
The NEJM palette is inspired by the plots in
The New England Journal of Medicine:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_nejm = p1 + scale_color_nejm()
p2_nejm = p2 + scale_fill_nejm()
grid.arrange(p1_nejm, p2_nejm, ncol = 2)
```
## Lancet
The Lancet palette is inspired by the plots in Lancet journals,
such as Lancet Oncology:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_lancet = p1 + scale_color_lancet()
p2_lancet = p2 + scale_fill_lancet()
grid.arrange(p1_lancet, p2_lancet, ncol = 2)
```
## JAMA
The JAMA palette is inspired by the plots in
The Journal of the American Medical Association:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_jama = p1 + scale_color_jama()
p2_jama = p2 + scale_fill_jama()
grid.arrange(p1_jama, p2_jama, ncol = 2)
```
## JCO
The JCO palette is inspired by the the plots in
Journal of Clinical Oncology:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_jco = p1 + scale_color_jco()
p2_jco = p2 + scale_fill_jco()
grid.arrange(p1_jco, p2_jco, ncol = 2)
```
## UCSCGB
The UCSCGB palette is from the colors used by
[UCSC Genome Browser](https://genome.ucsc.edu) for
representing chromosomes. This palette has been intensively
used in visualizations produced by [Circos](http://circos.ca).
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_ucscgb = p1 + scale_color_ucscgb()
p2_ucscgb = p2 + scale_fill_ucscgb()
grid.arrange(p1_ucscgb, p2_ucscgb, ncol = 2)
```
## D3
The D3 palette is from the categorical colors used by
[D3.js](https://d3js.org) (version 3.x and before).
There are four palette types (`category10`, `category20`,
`category20b`, `category20c`) available.
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_d3 = p1 + scale_color_d3()
p2_d3 = p2 + scale_fill_d3()
grid.arrange(p1_d3, p2_d3, ncol = 2)
```
## LocusZoom
The LocusZoom palette is based on the colors used by
[LocusZoom](http://locuszoom.org/).
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_locuszoom = p1 + scale_color_locuszoom()
p2_locuszoom = p2 + scale_fill_locuszoom()
grid.arrange(p1_locuszoom, p2_locuszoom, ncol = 2)
```
## IGV
The IGV palette is from the colors used by
[Integrative Genomics Viewer](http://software.broadinstitute.org/software/igv/)
for representing chromosomes. There are two palette types
(`default`, `alternating`) available.
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_igv_default = p1 + scale_color_igv()
p2_igv_default = p2 + scale_fill_igv()
grid.arrange(p1_igv_default, p2_igv_default, ncol = 2)
```
## UChicago
The UChicago palette is based on
[the colors](https://news.uchicago.edu/sites/default/files/attachments/_uchicago.identity.guidelines.pdf)
used by the University of Chicago.
There are three palette types (`default`, `light`, `dark`) available.
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_uchicago = p1 + scale_color_uchicago()
p2_uchicago = p2 + scale_fill_uchicago()
grid.arrange(p1_uchicago, p2_uchicago, ncol = 2)
```
## Star Trek
This palette is inspired by the (uniform) colors in Star Trek:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_startrek = p1 + scale_color_startrek()
p2_startrek = p2 + scale_fill_startrek()
grid.arrange(p1_startrek, p2_startrek, ncol = 2)
```
## Tron Legacy
This palette is inspired by the colors used in Tron Legacy.
It is suitable for displaying data when using a dark theme:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_tron = p1 + theme_dark() + theme(
panel.background = element_rect(fill = "#2D2D2D"),
legend.key = element_rect(fill = "#2D2D2D")) +
scale_color_tron()
p2_tron = p2 + theme_dark() + theme(
panel.background = element_rect(fill = "#2D2D2D")) +
scale_fill_tron()
grid.arrange(p1_tron, p2_tron, ncol = 2)
```
## Futurama
This palette is inspired by the colors used in the TV show Futurama:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_futurama = p1 + scale_color_futurama()
p2_futurama = p2 + scale_fill_futurama()
grid.arrange(p1_futurama, p2_futurama, ncol = 2)
```
## Rick and Morty
This palette is inspired by the colors used in the TV show Rick and Morty:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_rickandmorty = p1 + scale_color_rickandmorty()
p2_rickandmorty = p2 + scale_fill_rickandmorty()
grid.arrange(p1_rickandmorty, p2_rickandmorty, ncol = 2)
```
## The Simpsons
This palette is inspired by the colors used in the TV show
The Simpsons:
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
p1_simpsons = p1 + scale_color_simpsons()
p2_simpsons = p2 + scale_fill_simpsons()
grid.arrange(p1_simpsons, p2_simpsons, ncol = 2)
```
# Continuous Color Palettes
We will use a correlation matrix visualization (a special type of heatmap)
to demonstrate the continuous color palettes in `ggsci`.
```{r}
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
The GSEA palette (continuous) is inspired by the heatmaps generated by
[GSEA GenePattern](https://software.broadinstitute.org/cancer/software/genepattern/).
```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150}
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](https://material.io/guidelines/style/color.html).
We generate a random matrix first:
```{r}
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())
```
Plot the matrix with the 19 material design color palettes:
```{r, fig.width = 10.67, fig.height = 7.12, out.width = 800, out.height = 533, dpi = 150}
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)
```
From the figure above, we can see that even though an identical matrix
was visualized by all plots, some palettes are more preferrable
than the others because our eyes are more sensitive to the changes
of their saturation levels.
# Non-ggplot2 Graphics
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:
```{r, fig.width = 6.67, fig.height = 6.67, out.width = 500, out.height = 500, dpi = 150}
mypal = pal_npg("nrc", alpha = 0.7)(9)
mypal
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.
# Discussion
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](http://colorbrewer2.org)
and [viridis](https://cran.r-project.org/package=viridis).
The color palettes in this package are solely created for research purposes.
The authors are not responsible for the usage of such palettes.
ggsci/NAMESPACE 0000644 0001762 0000144 00000004070 13276174722 012601 0 ustar ligges users # Generated by roxygen2: do not edit by hand
export(pal_aaas)
export(pal_d3)
export(pal_futurama)
export(pal_gsea)
export(pal_igv)
export(pal_jama)
export(pal_jco)
export(pal_lancet)
export(pal_locuszoom)
export(pal_material)
export(pal_nejm)
export(pal_npg)
export(pal_rickandmorty)
export(pal_simpsons)
export(pal_startrek)
export(pal_tron)
export(pal_uchicago)
export(pal_ucscgb)
export(rgb_gsea)
export(rgb_material)
export(scale_color_aaas)
export(scale_color_d3)
export(scale_color_futurama)
export(scale_color_gsea)
export(scale_color_igv)
export(scale_color_jama)
export(scale_color_jco)
export(scale_color_lancet)
export(scale_color_locuszoom)
export(scale_color_material)
export(scale_color_nejm)
export(scale_color_npg)
export(scale_color_rickandmorty)
export(scale_color_simpsons)
export(scale_color_startrek)
export(scale_color_tron)
export(scale_color_uchicago)
export(scale_color_ucscgb)
export(scale_colour_aaas)
export(scale_colour_d3)
export(scale_colour_futurama)
export(scale_colour_gsea)
export(scale_colour_igv)
export(scale_colour_jama)
export(scale_colour_jco)
export(scale_colour_lancet)
export(scale_colour_locuszoom)
export(scale_colour_material)
export(scale_colour_nejm)
export(scale_colour_npg)
export(scale_colour_rickandmorty)
export(scale_colour_simpsons)
export(scale_colour_startrek)
export(scale_colour_tron)
export(scale_colour_uchicago)
export(scale_colour_ucscgb)
export(scale_fill_aaas)
export(scale_fill_d3)
export(scale_fill_futurama)
export(scale_fill_gsea)
export(scale_fill_igv)
export(scale_fill_jama)
export(scale_fill_jco)
export(scale_fill_lancet)
export(scale_fill_locuszoom)
export(scale_fill_material)
export(scale_fill_nejm)
export(scale_fill_npg)
export(scale_fill_rickandmorty)
export(scale_fill_simpsons)
export(scale_fill_startrek)
export(scale_fill_tron)
export(scale_fill_uchicago)
export(scale_fill_ucscgb)
importFrom(ggplot2,discrete_scale)
importFrom(ggplot2,scale_color_gradientn)
importFrom(ggplot2,scale_fill_gradientn)
importFrom(grDevices,col2rgb)
importFrom(grDevices,colorRamp)
importFrom(grDevices,rgb)
importFrom(scales,manual_pal)
ggsci/NEWS.md 0000644 0001762 0000144 00000001621 13276173326 012456 0 ustar ligges users # ggsci 2.9 (2018-05-13)
## Improvements
- New URL for the documentation website: https://nanx.me/ggsci/.
# ggsci 2.8 (2017-09-30)
## Improvements
- Use system font stack instead of Google Fonts in vignettes to avoid pandoc SSL issue.
# ggsci 2.7 (2017-06-12)
## New Features
Two new discrete color palettes:
- JAMA
- Tron Legacy
One new collection of continuous palettes with 19 color options:
- Material Design
# ggsci 2.4 (2017-03-07)
## New Features
Four new discrete color palettes:
- NEJM
- LocusZoom
- IGV
- Star Trek
# ggsci 2.0 (2016-11-20)
## New Features
Two new discrete color palettes:
- D3.js (v3)
- Futurama (Planet Express)
The first continuous color palette:
- GSEA GenePattern
# ggsci 1.0 (2016-04-01)
## New Features
Eight discrete color palettes:
- NPG
- AAAS
- Lancet
- JCO
- UCSCGB
- UChicago
- The Simpsons (Springfield)
- Rick and Morty (Schwifty)
ggsci/R/ 0000755 0001762 0000144 00000000000 13221611720 011542 5 ustar ligges users ggsci/R/discrete-ucscgb.R 0000644 0001762 0000144 00000004761 13221611720 014743 0 ustar ligges users #' UCSC Genome Browser Color Palette
#'
#' Color palette from UCSC Genome Browser chromosome colors.
#'
#' @param palette Palette type.
#' Currently there is one available option: \code{"default"}
#' (26-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_ucscgb
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @examples
#' library("scales")
#' show_col(pal_ucscgb("default")(26))
#' show_col(pal_ucscgb("default", alpha = 0.6)(26))
pal_ucscgb = function (palette = c('default'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'ucscgb'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' UCSC Genome Browser Color Scales
#'
#' See \code{\link{pal_ucscgb}} for details.
#'
#' @inheritParams pal_ucscgb
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_ucscgb
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @rdname scale_ucscgb
#'
#' @examples
#' library("ggplot2")
#' data("diamonds")
#'
#' ggplot(subset(diamonds, carat >= 2.2),
#' aes(x = table, y = price, colour = cut)) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_ucscgb()
#'
#' 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() + scale_fill_ucscgb()
scale_color_ucscgb = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'ucscgb', pal_ucscgb(palette, alpha), ...)
}
#' @export scale_colour_ucscgb
#' @rdname scale_ucscgb
scale_colour_ucscgb = scale_color_ucscgb
#' @export scale_fill_ucscgb
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_ucscgb
scale_fill_ucscgb = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'ucscgb', pal_ucscgb(palette, alpha), ...)
}
ggsci/R/discrete-locuszoom.R 0000644 0001762 0000144 00000005316 13221611720 015524 0 ustar ligges users #' LocusZoom Color Palette
#'
#' Color palettes based on the colors used by LocusZoom.
#'
#' @param palette Palette type.
#' Currently there is one available option: \code{"default"}
#' (7-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_locuszoom
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references
#' Pruim, Randall J., et al. (2010). LocusZoom: regional visualization of
#' genome-wide association scan results. \emph{Bioinformatics},
#' 26(18), 2336--2337.
#'
#' @examples
#' library("scales")
#' show_col(pal_locuszoom("default")(7))
#' show_col(pal_locuszoom("default", alpha = 0.6)(7))
pal_locuszoom = function (palette = c('default'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'locuszoom'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' LocusZoom Color Scales
#'
#' See \code{\link{pal_locuszoom}} for details.
#'
#' @inheritParams pal_locuszoom
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_locuszoom
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @rdname scale_locuszoom
#'
#' @examples
#' library("ggplot2")
#' data("diamonds")
#'
#' ggplot(subset(diamonds, carat >= 2.2),
#' aes(x = table, y = price, colour = cut)) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_locuszoom()
#'
#' 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() + scale_fill_locuszoom()
scale_color_locuszoom = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'locuszoom', pal_locuszoom(palette, alpha), ...)
}
#' @export scale_colour_locuszoom
#' @rdname scale_locuszoom
scale_colour_locuszoom = scale_color_locuszoom
#' @export scale_fill_locuszoom
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_locuszoom
scale_fill_locuszoom = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'locuszoom', pal_locuszoom(palette, alpha), ...)
}
ggsci/R/discrete-uchicago.R 0000644 0001762 0000144 00000006236 13276174433 015275 0 ustar ligges users #' The University of Chicago Color Palettes
#'
#' Color palettes based on the colors used by the University of Chicago.
#'
#' @param palette Palette type.
#' There are 3 available options:
#' \code{"default"} (9-color palette);
#' \code{"light"} (9-color light palette);
#' \code{"dark"} (9-color dark palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_uchicago
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references \url{https://news.uchicago.edu/sites/default/files/attachments/_uchicago.identity.guidelines.pdf}
#'
#' @examples
#' library("scales")
#' show_col(pal_uchicago("default")(9))
#' show_col(pal_uchicago("light")(9))
#' show_col(pal_uchicago("dark")(9))
pal_uchicago = function (
palette = c('default', 'light', 'dark'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'uchicago'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' The University of Chicago Color Scales
#'
#' See \code{\link{pal_uchicago}} for details.
#'
#' @inheritParams pal_uchicago
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_uchicago
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references \url{https://news.uchicago.edu/sites/default/files/attachments/_uchicago.identity.guidelines.pdf}
#'
#' @rdname scale_uchicago
#'
#' @examples
#' library("ggplot2")
#' 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.1, 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()
#'
#' p1 + scale_color_uchicago()
#' p2 + scale_fill_uchicago()
#'
#' p1 + scale_color_uchicago(palette = "light")
#' p2 + scale_fill_uchicago(palette = "light")
#'
#' p1 + scale_color_uchicago(palette = "dark")
#' p2 + scale_fill_uchicago(palette = "dark")
scale_color_uchicago = function (
palette = c('default', 'light', 'dark'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'uchicago', pal_uchicago(palette, alpha), ...)
}
#' @export scale_colour_uchicago
#' @rdname scale_uchicago
scale_colour_uchicago = scale_color_uchicago
#' @export scale_fill_uchicago
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_uchicago
scale_fill_uchicago = function (
palette = c('default', 'light', 'dark'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'uchicago', pal_uchicago(palette, alpha), ...)
}
ggsci/R/discrete-igv.R 0000644 0001762 0000144 00000005741 13221611720 014261 0 ustar ligges users #' Integrative Genomics Viewer (IGV) Color Palettes
#'
#' Color palettes based on the colors used by
#' Integrative Genomics Viewer (IGV).
#'
#' @param palette Palette type.
#' There are two available options:
#' \code{"default"} (51-color palette);
#' \code{"alternating"} (2-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_igv
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references
#' James T. Robinson, Helga Thorvaldsd\'{o}ttir, Wendy Winckler,
#' Mitchell Guttman, Eric S. Lander, Gad Getz, Jill P. Mesirov.
#' Integrative Genomics Viewer. \emph{Nature Biotechnology} 29, 24--26 (2011).
#'
#' @examples
#' library("scales")
#' show_col(pal_igv("default")(51))
#' show_col(pal_igv("alternating")(2))
pal_igv = function (
palette = c('default', 'alternating'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'igv'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' Integrative Genomics Viewer (IGV) Color Scales
#'
#' See \code{\link{pal_igv}} for details.
#'
#' @inheritParams pal_igv
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_igv
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @rdname scale_igv
#'
#' @examples
#' library("ggplot2")
#' 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.1, 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()
#'
#' p1 + scale_color_igv()
#' p2 + scale_fill_igv()
#'
#' p1 + scale_colour_manual(
#' values = rep(pal_igv("alternating")(2), times = 3))
#' p2 + scale_fill_manual(
#' values = rep(pal_igv("alternating")(2), times = 3))
scale_color_igv = function (
palette = c('default', 'alternating'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'igv', pal_igv(palette, alpha), ...)
}
#' @export scale_colour_igv
#' @rdname scale_igv
scale_colour_igv = scale_color_igv
#' @export scale_fill_igv
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_igv
scale_fill_igv = function (
palette = c('default', 'alternating'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'igv', pal_igv(palette, alpha), ...)
}
ggsci/R/discrete-d3.R 0000644 0001762 0000144 00000006376 13221611720 014007 0 ustar ligges users #' D3.js Color Palettes
#'
#' Color palettes based on the colors used by D3.js.
#'
#' @param palette Palette type.
#' There are 4 available options:
#' \code{"category10"} (10-color palette);
#' \code{"category20"} (20-color palette);
#' \code{"category20b"} (20-color palette);
#' \code{"category20c"} (20-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_d3
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references \url{https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md}
#'
#' @examples
#' library("scales")
#' show_col(pal_d3("category10")(10))
#' show_col(pal_d3("category20")(20))
#' show_col(pal_d3("category20b")(20))
#' show_col(pal_d3("category20c")(20))
pal_d3 = function (
palette = c('category10', 'category20',
'category20b', 'category20c'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'d3'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' D3.js Color Scales
#'
#' See \code{\link{pal_d3}} for details.
#'
#' @inheritParams pal_d3
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_d3
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @references \url{https://github.com/d3/d3-3.x-api-reference/blob/master/Ordinal-Scales.md}
#'
#' @rdname scale_d3
#'
#' @examples
#' library("ggplot2")
#' 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.1, 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()
#'
#' p1 + scale_color_d3()
#' p2 + scale_fill_d3()
#'
#' p1 + scale_color_d3(palette = "category20")
#' p2 + scale_fill_d3(palette = "category20")
#'
#' p1 + scale_color_d3(palette = "category20b")
#' p2 + scale_fill_d3(palette = "category20b")
#'
#' p1 + scale_color_d3(palette = "category20c")
#' p2 + scale_fill_d3(palette = "category20c")
scale_color_d3 = function (
palette = c('category10', 'category20',
'category20b', 'category20c'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'd3', pal_d3(palette, alpha), ...)
}
#' @export scale_colour_d3
#' @rdname scale_d3
scale_colour_d3 = scale_color_d3
#' @export scale_fill_d3
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_d3
scale_fill_d3 = function (
palette = c('category10', 'category20',
'category20b', 'category20c'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'd3', pal_d3(palette, alpha), ...)
}
ggsci/R/discrete-nejm.R 0000644 0001762 0000144 00000004673 13221611720 014430 0 ustar ligges users #' NEJM Color Palettes
#'
#' Color palette inspired by plots in
#' \emph{The New England Journal of Medicine}.
#'
#' @param palette Palette type.
#' Currently there is one available option: \code{"default"}
#' (8-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
#' @export pal_nejm
#'
#' @importFrom grDevices col2rgb rgb
#' @importFrom scales manual_pal
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @examples
#' library("scales")
#' show_col(pal_nejm("default")(8))
#' show_col(pal_nejm("default", alpha = 0.6)(8))
pal_nejm = function (palette = c('default'), alpha = 1) {
palette = match.arg(palette)
if (alpha > 1L | alpha <= 0L) stop('alpha must be in (0, 1]')
raw_cols = ggsci_db$'nejm'[[palette]]
raw_cols_rgb = col2rgb(raw_cols)
alpha_cols = rgb(
raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ],
alpha = alpha * 255L, names = names(raw_cols),
maxColorValue = 255L)
manual_pal(unname(alpha_cols))
}
#' NEJM Color Scales
#'
#' See \code{\link{pal_nejm}} for details.
#'
#' @inheritParams pal_nejm
#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}}
#'
#' @export scale_color_nejm
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#'
#' @rdname scale_nejm
#'
#' @examples
#' library("ggplot2")
#' data("diamonds")
#'
#' ggplot(subset(diamonds, carat >= 2.2),
#' aes(x = table, y = price, colour = cut)) +
#' geom_point(alpha = 0.7) +
#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) +
#' theme_bw() + scale_color_nejm()
#'
#' 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() + scale_fill_nejm()
scale_color_nejm = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('colour', 'nejm', pal_nejm(palette, alpha), ...)
}
#' @export scale_colour_nejm
#' @rdname scale_nejm
scale_colour_nejm = scale_color_nejm
#' @export scale_fill_nejm
#' @importFrom ggplot2 discrete_scale
#' @rdname scale_nejm
scale_fill_nejm = function (palette = c('default'), alpha = 1, ...) {
palette = match.arg(palette)
discrete_scale('fill', 'nejm', pal_nejm(palette, alpha), ...)
}
ggsci/R/sysdata.rda 0000644 0001762 0000144 00000011671 13221611720 013710 0 ustar ligges users \[sƱVDI*yJyv
;17;舊c.a-,|*,5.3g;rgϞ?;:~Q>{gb=kw>\y{u/ )!Z̔!5)5BO-+rFX67dd9YaŋUu[iV}=⋫C~]uSz5vSݾkforv5gnWTݲ$߶ʴUw&<7^hN լ("s%e,H\/:H>B9/Ke\Df*{sy1y|)M]~8{(Lo7^f^߸nYTCgM;a_ja4e!H$:R$)\h%T_c[SSf
9ЏwrȽu}gn끋sUvI{>4Wղm=,f7ouh<ޘP̜MNsQ ѩx[z"%@-t4;tҴE0uOS}Q-5p@ML4mY2f5p?V|