R Scientific Research Drawing Palette—ggsci

R Scientific Research Drawing Palette—ggsci

ggsci is a package in R that provides a series of colors for grading ggplot2. It includes the classic color matching styles of some well-known magazines or software (even well-known science fiction movies, animation, etc.), which is quite helpful for scientific research drawing. Let’s introduce the usage and content of this package. If you want to check the description yourself, you can enter it in R

vignette("ggsci")

Come for a quick look. 1. you can download ggsci in the following two ways:

# download ggsci package
install.packages("ggsci")

#install.packages("devtools")
devtools::install_github("nanxstats/ggsci")

After downloading, you can use the diamonds data set to see the color matching effect:

library(ggsci)
library(ggplot2)
library(gridExtra)

data('diamonds')

The main contents of the diamonds data set are:

image

Since the original data is too large, we will filter the data before drawing, first use ggplot to make scatter plots and boxplots:

# Scatter chart
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

# Box plot
p2 = ggplot(subset(diamonds, carat> 2.2), aes(x = color, y = price, fill = color)) + geom_boxplot(color ='black') + theme_bw()
p2

Scatter chart:

image

Box plot:

image

The following is color matching according to scale_color_xx or scale_fill_xx in ggsci (xx is the name of the magazine or software).

New England Magazine (NEJM):

p1_nejm = p1 + scale_color_nejm()

image

Lancet:

p1_lancet = p1 + scale_color_lancet()

image

Genome visualization software IGV:

p1_igv = p1 + scale_color_igv()

image

Well-known animation Rick and Morty:

p1_rick = p1 + scale_color_rickandmorty()

image

Science fiction movie Tron: Legacy:

p1_tron = p1 + theme_dark() + scale_color_tron()

image

There are some other color schemes that are not shown. If you are interested, you can check and explore by yourself~

Learn more about life letter/programming knowledge, welcome to pay attention~

Reference: https://cloud.tencent.com/developer/article/1607812 R Scientific Drawing Palette-ggsci-Cloud + Community-Tencent Cloud