viridis - 印花和色盲友好的調色盤
Viridis(以 chromis viridis 魚命名 )是最近開發的 Python 庫 matplotlib
的配色方案 (連結的視訊演示解釋了配色方案是如何開發的以及它的主要優點)。它被無縫移植到 R
。
顏色方案有 4 種顏色:magma
,plasma
,inferno
和 viridis
(預設)。它們與 option
引數一起選擇,並相應地編碼為 A
,B
,C
和 D
。要了解 4 種配色方案,請檢視地圖:
https://i.stack.imgur.com/YwZHn.jpg ( 影象源 )
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)