Good figure design is half about color. Scientific figures have extra requirements: readable by colorblind readers, distinguishable in grayscale print, and meeting journal resolution standards. Below are 5 practical schemes I accumulated while writing papers, each with complete R code.
Why not use ggplot2 default colors?
ggplot2's default rainbow color wheel has two major flaws: red-green colorblind people cannot distinguish them (about 8% of men globally), and when printed in grayscale, the brightness differences between colors are minimal, making them nearly indistinguishable. These issues appear in reviewer comments far more often than you'd expect.
Scheme 1: viridis (colorblind-safe + gradient first choice)
library(viridis)
library(ggplot2)
# Continuous variable (e.g., heatmap)
ggplot(df, aes(x, y, fill=value)) +
geom_tile() +
scale_fill_viridis_c()
# Discrete variable
ggplot(df, aes(x, y, color=group)) +
geom_point() +
scale_color_viridis_d(option="D") # also "magma", "plasma"
viridis is currently the most common color scheme in Nature and Science sub-journals. It is colorblind-safe and has clear layering in grayscale.
Scheme 2: ColorBrewer (first choice for categorical variables)
scale_color_brewer(palette = "Set2") # 8 colors, soft
scale_color_brewer(palette = "Dark2") # 8 colors, dark version
scale_fill_brewer(palette = "Blues") # single-hue gradient
At colorbrewer2.org you can preview all palettes and filter by "Colorblind safe".
Scheme 3: ggsci journal palettes
library(ggsci)
scale_color_nejm() # NEJM style: blue, red, black
scale_color_lancet() # Lancet style
scale_color_jco() # JCO style (oncology journal)
scale_color_npg() # Nature series
When submitting to life science journals, using the corresponding journal's color style makes reviewers feel at home and creates a more unified visual appearance.
Scheme 4: Manual definition (most controllable)
# Pick 4 colors (tune with Adobe Color or coolors.co)
my_colors <- c("#E64B35", "#4DBBD5", "#00A087", "#3C5488")
scale_color_manual(values = my_colors)
scale_fill_manual(values = my_colors)
The advantage is that all figures use exactly the same colors, giving your paper the strongest visual consistency.
Scheme 5: Colorblind check before submission
install.packages("colorblindr")
library(colorblindr)
p <- ggplot(df, aes(x, y, color=group)) + geom_point()
cvd_grid(p) # simulates red-green + blue-yellow colorblindness + grayscale, 4 views
Run this before submission to confirm that groups are still distinguishable under colorblind vision. This step can prevent reviewers from specifically pointing out "Figure X is not colorblind-friendly."
文章评论