viridis - 印花和色盲友好的调色板

Viridis(以 chromis viridis 鱼命名 )是最近开发的 Python 库 matplotlib 的配色方案 (链接的视频演示解释了配色方案是如何开发的以及它的主要优点)。它被无缝移植到 R

颜色方案有 4 种颜色:magmaplasmainfernoviridis(默认)。它们与 option 参数一起选择,并相应地编码为 ABCD。要了解 4 种配色方案,请查看地图:

https://i.stack.imgur.com/YwZHn.jpg图像源

该软件包可以从 CRANgithub 安装。

viridis 包装的插图非常精彩。

viridis 配色方案的优点是与 ggplot2 的集成。在包中,定义了两个特定于 ggplot2 的函数:scale_color_viridis()scale_fill_viridis()。请参阅以下示例:

library(viridis)
library(ggplot2)

gg1 <- ggplot(mtcars)+
    geom_point(aes(x = mpg, y = hp, color = disp), size = 3)+
    scale_color_viridis(option = "B")+
    theme_minimal()+
    theme(legend.position = c(.8,.8))

gg2 <- ggplot(mtcars)+
        geom_violin(aes(x = factor(cyl), y = hp, fill = factor(cyl)))+
        scale_fill_viridis(discrete = T)+
        theme_minimal()+
        theme(legend.position = 'none')

library(cowplot)
output <- plot_grid(gg1,gg2, labels = c('B','D'),label_size = 20)
print(output)

StackOverflow 文档