2025年色彩 - R 语言中的渐变色- viridis 包(色盲友好的颜色包)

色彩 - R 语言中的渐变色- viridis 包(色盲友好的颜色包)viridis v r d s n 翠绿色 该包提供了一系列 色盲友好的颜色 Robust to colorblindne so that the above properties hold true for people with common forms of colorblindne as well as in grey scale printing and

大家好,我是讯享网,很高兴认识大家。

viridis [ˈvɪrɪˌdɪs] n.翠绿色;

该包提供了一系列 色盲友好的颜色。
Robust to colorblindness, so that the above properties hold true for people with common forms of colorblindness, as well as in grey scale printing, and
Pretty, oh so pretty

install.packages("viridis") 

讯享网

1.生成颜色实例: 参数类似

讯享网library(viridis) #c1=viridis(n=10, alpha = 1, begin = 0, end = 1, direction = 1); c1 c1=viridis(10, alpha = 1, begin = 0, end = 1, direction = 1, option = "A"); c1 # n 色彩个数 # alpha 不透明度,1表示完全不透明,0表示完全透明。 # begin 和 end 表示 hue 开始和结束的位置[0,1] # direction 颜色方向,1从深到浅,-1反之。 # option 表示8种颜色方案,可以换前面的函数名,也可以换 option 种的字母A-H barplot( rep(1, length(c1)), col=c1, border=NA, yaxt='n', space=0, main="") 

在这里插入图片描述
讯享网

2.官方教程

library(ggplot2) ggplot(data.frame(x = rnorm(10000), y = rnorm(10000)), aes(x = x, y = y)) + geom_hex() + coord_fixed() + scale_fill_viridis() + theme_bw() 

在这里插入图片描述

3.查看8种颜色方案

讯享网draw=function(colorname, title="", n=100){ if(title==""){ title=paste0(colorname, ", n=", n) } #print(title) cols=do.call(colorname, list(n, alpha = 1, begin = 0, end = 1, direction = -1) ) barplot( rep(1, length(cols)), col=cols, border=NA, yaxt='n', space=0, main=title) } par(mfrow=c(8,2), mar=c(0,0,1.5,0) ) for(i in c("viridis", "magma", "inferno", "plasma", "cividis", "rocket", "mako", "turbo")){ print(i) draw(i, n=10) draw(i, n=100) } 

8种渐变色

4.热图

前7种渐变色都特别适合热图。

set.seed(2022) test = matrix(rnorm(200), 20, 10) test[1:10, seq(1, 10, 2)] = test[1:10, seq(1, 10, 2)] + 3 test[11:20, seq(2, 10, 2)] = test[11:20, seq(2, 10, 2)] + 2 test[15:20, seq(2, 10, 2)] = test[15:20, seq(2, 10, 2)] + 4 colnames(test) = paste("Test", 1:10, sep = "") rownames(test) = paste("Gene", 1:20, sep = "") # dim(test) # Draw heatmaps library(pheatmap) pheatmap(test) 

在这里插入图片描述

讯享网# viridis pheatmap(test, color = viridis(8), main="viridis") 

在这里插入图片描述

# mako pheatmap(test, color = viridis(8, option = "G"), main="mako") 

在这里插入图片描述

ref

https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html

== End ==

小讯
上一篇 2025-01-27 09:43
下一篇 2025-03-19 09:50

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/55448.html