服务器画热图显示无效的变量,使用pheatmap包绘制热图

news2023/12/2 7:28:20

加载所需R包

library(pheatmap)

设置工作路径

setwd("/Users/Davey/Desktop/VennDiagram/")

# 清除当前环境中的变量

rm(list=ls())

构建测试数据集

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 = "")

head(test)

## Test1 Test2 Test3 Test4 Test5 Test6

## Gene1 4.064973 0.7535271 3.024070 -2.1294440 4.407945 -0.35677097

## Gene2 2.360043 1.6974946 3.273425 -2.3341406 3.839523 0.16982944

## Gene3 3.253465 -0.9011582 1.716257 -0.2294471 4.636610 -0.24520382

## Gene4 4.070226 -0.6191941 3.734437 1.9348314 4.426825 -0.17730957

## Gene5 3.821414 0.5584876 1.871479 -0.2784607 2.633761 0.01332901

## Gene6 3.012469 0.1738285 3.652423 -2.0083435 4.124951 -0.67899611

## Test7 Test8 Test9 Test10

## Gene1 3.602764 1.2903843 2.044119 1.826159e+00

## Gene2 3.083160 0.2642755 2.855381 1.988289e-01

## Gene3 3.417809 -0.1362079 3.858884 -8.390304e-01

## Gene4 2.911934 0.4299550 4.128398 -3.011521e+00

## Gene5 2.651758 -1.6884728 3.001079 1.861780e+00

## Gene6 1.934270 0.5811059 2.297763 6.878644e-05

# 默认绘图

pheatmap(test)

1c55ea64ff3f

image.png

# scale = "row"参数对行进行归一化

pheatmap(test, scale = "row")

1c55ea64ff3f

image.png

# clustering_method参数设定不同聚类方法,默认为"complete",可以设定为'ward', 'ward.D', 'ward.D2', 'single', 'complete', 'average', 'mcquitty', 'median' or 'centroid'

pheatmap(test,scale = "row", clustering_method = "average")

1c55ea64ff3f

image.png

# clustering_distance_rows = "correlation"参数设定行聚类距离方法为Pearson corralation,默认为欧氏距离"euclidean"

pheatmap(test, scale = "row", clustering_distance_rows = "correlation")

1c55ea64ff3f

image.png

# color参数自定义颜色

pheatmap(test, color = colorRampPalette(c("navy", "white", "firebrick3"))(50))

1c55ea64ff3f

image.png

# cluster_row = FALSE参数设定不对行进行聚类

pheatmap(test, cluster_row = FALSE)

1c55ea64ff3f

image.png

# legend_breaks参数设定图例显示范围,legend_labels参数添加图例标签

pheatmap(test, legend_breaks = c(1:5), legend_labels = c("1.0","2.0","3.0","4.0","5.0"))

1c55ea64ff3f

image.png

# legend = FALSE参数去掉图例

pheatmap(test, legend = FALSE)

1c55ea64ff3f

image.png

# border_color参数设定每个热图格子的边框色

pheatmap(test, border_color = "red")

1c55ea64ff3f

image.png

# border=FALSE参数去掉边框线

pheatmap(test, border=FALSE)

1c55ea64ff3f

image.png

# show_rownames和show_colnames参数设定是否显示行名和列名

pheatmap(test,show_rownames=F,show_colnames=F)

1c55ea64ff3f

image.png

# treeheight_row和treeheight_col参数设定行和列聚类树的高度,默认为50

pheatmap(test, treeheight_row = 30, treeheight_col = 50)

1c55ea64ff3f

image.png

# display_numbers = TRUE参数设定在每个热图格子中显示相应的数值,number_color参数设置数值字体的颜色

pheatmap(test, display_numbers = TRUE,number_color = "blue")

1c55ea64ff3f

image.png

# number_format = "%.1e"参数设定数值的显示格式

pheatmap(test, display_numbers = TRUE, number_format = "%.1e")

1c55ea64ff3f

image.png

# 自定义数值的显示方式

pheatmap(test, display_numbers = matrix(ifelse(test > 5, "*", ""), nrow(test)))

1c55ea64ff3f

image.png

# cellwidth和cellheight参数设定每个热图格子的宽度和高度,main参数添加主标题

pheatmap(test, cellwidth = 15, cellheight = 12, main = "Example heatmap")

1c55ea64ff3f

image.png

# 构建列注释信息

annotation_col = data.frame(

CellType = factor(rep(c("CT1", "CT2"), 5)),

Time = 1:5

)

rownames(annotation_col) = paste("Test", 1:10, sep = "")

head(annotation_col)

## CellType Time

## Test1 CT1 1

## Test2 CT2 2

## Test3 CT1 3

## Test4 CT2 4

## Test5 CT1 5

## Test6 CT2 1

# 构建行注释信息

annotation_row = data.frame(

GeneClass = factor(rep(c("Path1", "Path2", "Path3"), c(10, 4, 6)))

)

rownames(annotation_row) = paste("Gene", 1:20, sep = "")

head(annotation_row)

## GeneClass

## Gene1 Path1

## Gene2 Path1

## Gene3 Path1

## Gene4 Path1

## Gene5 Path1

## Gene6 Path1

# annotation_col参数添加列注释信息

pheatmap(test, annotation_col = annotation_col)

1c55ea64ff3f

image.png

# annotation_legend = FALSE参数去掉注释图例

pheatmap(test, annotation_col = annotation_col, annotation_legend = FALSE)

1c55ea64ff3f

image.png

# annotation_col和annotation_row参数同时添加行和列的注释信息

pheatmap(test, annotation_row = annotation_row, annotation_col = annotation_col)

1c55ea64ff3f

image.png

# 自定注释信息的颜色列表

ann_colors = list(

Time = c("white", "firebrick"),

CellType = c(CT1 = "#1B9E77", CT2 = "#D95F02"),

GeneClass = c(Path1 = "#7570B3", Path2 = "#E7298A", Path3 = "#66A61E")

)

head(ann_colors)

## $Time

## [1] "white" "firebrick"

##

## $CellType

## CT1 CT2

## "#1B9E77" "#D95F02"

##

## $GeneClass

## Path1 Path2 Path3

## "#7570B3" "#E7298A" "#66A61E"

# annotation_colors设定注释信息的颜色

pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors, main = "Title")

1c55ea64ff3f

image.png

pheatmap(test, annotation_col = annotation_col, annotation_row = annotation_row,

annotation_colors = ann_colors)

1c55ea64ff3f

image.png

pheatmap(test, annotation_col = annotation_col, annotation_colors = ann_colors[2])

1c55ea64ff3f

image.png

# gaps_row = c(10, 14)参数在第10和14行处添加gap, 要求对行不进行聚类

pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14))

1c55ea64ff3f

image.png

# cutree_col = 2参数将列按聚类树的结果分成两部分, 要求对列进行聚类

pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, gaps_row = c(10, 14),

cutree_col = 2)

1c55ea64ff3f

image.png

# 对行和列都不聚类,自定义划分行和列的gap

pheatmap(test, annotation_col = annotation_col, cluster_rows = FALSE, cluster_cols = FALSE,

gaps_row = c(6, 10, 14), gaps_col = c(2, 5, 8))

1c55ea64ff3f

image.png

# 自定义行的标签名

labels_row = c("", "", "", "", "", "", "", "", "", "", "", "", "", "", "",

"", "", "Il10", "Il15", "Il1b")

# labels_row参数添加行标签

pheatmap(test, annotation_col = annotation_col, labels_row = labels_row)

1c55ea64ff3f

image.png

# 自定义聚类的距离方法

drows = dist(test, method = "minkowski")

dcols = dist(t(test), method = "minkowski")

# clustering_distance_rows和clustering_distance_cols参数设定行和列的聚类距离方法

pheatmap(test, clustering_distance_rows = drows, clustering_distance_cols = dcols)

1c55ea64ff3f

image.png

# fontsize参数设定标签字体大小,filename参数设定图片保存名称

pheatmap(test, cellwidth = 15, cellheight = 12, fontsize = 8, filename = "test.pdf")

将热图结果按聚类后的顺序输出

aa=pheatmap(test,scale="row") #热图,归一化,并聚类

1c55ea64ff3f

image.png

# 简要查看热图对象的信息

summary(aa)

## Length Class Mode

## tree_row 7 hclust list

## tree_col 7 hclust list

## kmeans 1 -none- logical

## gtable 6 gtable list

order_row = aa$tree_row$order #记录热图的行排序

order_col = aa$tree_col$order #记录热图的列排序

datat = data.frame(test[order_row,order_col]) # 按照热图的顺序,重新排原始数据

datat = data.frame(rownames(datat),datat,check.names =F) # 将行名加到表格数据中

colnames(datat)[1] = "geneid"

write.table(datat,file="reorder.txt",row.names=FALSE,quote = FALSE,sep='\t') #输出结果,按照热图中的顺序

sessionInfo()

## R version 3.5.1 (2018-07-02)

## Platform: x86_64-apple-darwin15.6.0 (64-bit)

## Running under: OS X El Capitan 10.11.3

##

## Matrix products: default

## BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib

## LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

##

## locale:

## [1] zh_CN.UTF-8/zh_CN.UTF-8/zh_CN.UTF-8/C/zh_CN.UTF-8/zh_CN.UTF-8

##

## attached base packages:

## [1] stats graphics grDevices utils datasets methods base

##

## other attached packages:

## [1] pheatmap_1.0.10

##

## loaded via a namespace (and not attached):

## [1] Rcpp_0.12.18 digest_0.6.16 rprojroot_1.3-2

## [4] grid_3.5.1 gtable_0.2.0 backports_1.1.2

## [7] magrittr_1.5 scales_1.0.0 evaluate_0.11

## [10] stringi_1.2.4 rmarkdown_1.10 RColorBrewer_1.1-2

## [13] tools_3.5.1 stringr_1.3.1 munsell_0.5.0

## [16] yaml_2.2.0 compiler_3.5.1 colorspace_1.3-2

## [19] htmltools_0.3.6 knitr_1.20

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://nwjs.net/news/299904.html

如若内容造成侵权/违法违规/事实不符,请联系七分地网进行投诉反馈,一经查实,立即删除!

相关文章

QQ圈子:从哪里来,到哪里去

2019独角兽企业重金招聘Python工程师标准>>> 摆脱顿巴数的魔咒 社 交是人类的一个最基本的需求。但是,自然给我们人类的大脑,只能让我们维系150-200个左右的好友。超出这个范围,就会有好友慢慢地被淡忘。很多社会 群体的平均大小是…

sap系统搭建教程_Nios ii最小系统搭建教程

本教程以最小系统的概念为切入点,详细演示最小系统搭建的每一个步骤;外加嵌入式IP CORE详细的理论剖析和详细的实践演示,提供部分工程集源码下载链接。本手稿为实践总结,只是提供了一个思路,比如,驱动都是基…

旷视5号员工陈可卿:1991生于绍兴、10岁买电脑改变命运,信息奥赛金牌保送清华...

允中 发自 融科资讯中心 量子位 出品 | 公众号 QbitAI陈可卿,28岁,旷视创始员工,工号No.5。他生于1991年,曾是信息学奥赛金牌选手,高中保送进清华。大二以实习生身份进旷视,是创始员工之一,实习…

Jquery--遮罩弹窗特效

/*! jQuery v1.7.2 jquery.com | jquery.org/license */ (function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType9?a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var bc.body,df("<"a">").appendTo(b),ed.css("di…

怀旧服湖畔镇服务器位置,《魔兽世界怀旧服》今天再开10组新服 47组服务器免费转服开启...

原标题&#xff1a;《魔兽世界怀旧服》今天再开10组新服 47组服务器免费转服开启为了进一步缓解服务器压力《魔兽世界怀旧服》官方今天再次开放10组新服务器&#xff0c;同时前段时间承诺的47组服务器的免费免费角色转移服务也在今天上线了。《魔兽世界怀旧服》开服至今服务器的…

万分之二用百分之怎么表示_2020年元旦放假通知!周三放1天!不挪假连休,你打算怎么安排?...

2020年元旦放假安排通知根据国务院办公厅通知精神&#xff0c;现将2020年元旦放假安排通知如下&#xff1a; 2020年1月1日(星期三)放假1天。请广大市民提前安排好工作生活&#xff0c;节日期间注意安全&#xff0c;度过一个欢乐、祥和的节日假期。对于这样的安排不少网友表示既…

泉州服务器维修,泉州云服务器

泉州云服务器 内容精选换一换华为云云服务器备份视频帮助&#xff0c;为用户提供创建云服务器备份和使用云服务器备份恢复云服务器等操作视频&#xff0c;帮助您快速上手使用云服务器备份。登录华为云官网&#xff0c;选择“控制台”。选择弹性云服务器所在的区域。选择“计算 …

特斯联再获20亿元融资,跻身AIoT独角兽,光大京东讯飞万达入股

雷刚 发自 凹非寺 量子位 报道 | 公众号 QbitAIAIoT领域玩家特斯联&#xff0c;成为新晋独角兽。今日&#xff08;8月12日&#xff09;&#xff0c;特斯联宣布完成C1轮融资。本轮融资金额为20亿元人民币&#xff0c;由光大控股领投&#xff0c;京东、科大讯飞、万达投资等跟投。…

esnext:最后一个参数后面也允许加逗号了

https://jeffmo.github.io/es-trailing-function-commas 目前是一个 stage 3 的提案&#xff0c;Chakra 和 JSC 已经实现了&#xff0c;它允许我们在函数定义时的最后一个形参和函数调用时的最后一个实参的尾部加上逗号。 最后一个参数加上逗号有什么优点&#xff1f; 注意&…

Ov

Ov posted on 2016-10-21 17:31 秦瑞It行程实录 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/ruiy/p/5985472.html

Linux文件系统只读Read-only file system

问题描述:1、系统无法进行磁盘的读写操作&#xff08;touch,cp,chmod&#xff09;等等2、服务器无法启动&#xff08;也是因为无法创建文件&#xff09;3、只有涉及到系统磁盘的写操作&#xff0c;都会报错"Read-only file system"问题原因&#xff1a;1、系统没有正…

怎么用u盘在服务器上传文件,U盘向云服务器传输文件吗

U盘向云服务器传输文件吗 内容精选换一换使用云服务器备份创建镜像后&#xff0c;通过创建成功的镜像创建云服务器&#xff0c;但登录云服务器后提示系统进入维护模式&#xff0c;无法正常使用云服务器。当云服务器带有数据盘的时候&#xff0c;恢复后的云服务器中的系统盘/etc…

五行代码玩转GPT-2,新加坡高中生开源轻量级GPT-2“客户端”

鱼羊 发自 凹非寺 量子位 报道 | 公众号 QbitAIOpenAI会讲故事的文本生成模型GPT-2&#xff0c;现在有了更易用的封装版本。轻松上手&#xff0c;轻量级&#xff0c;速度快。这就是这只名叫gpt2-client的包装器的突出特性。作者小哥 Rishabh Anand 表示&#xff0c;gpt2-client…

什么叫取反_转载:CodeReview正确的姿势是什么?

作者&#xff1a;微博是阿里孤尽链接&#xff1a;https://www.zhihu.com/question/383079175/answer/1109655276来源&#xff1a;知乎著作权归作者所有。商业转载请联系作者获得授权&#xff0c;非商业转载请注明出处。CodeReview正确的姿势是什么&#xff1f;​www.zhihu.com全…

GitHub免费支持CI/CD了,开发测试部署高度自动化,支持各种语言,网友:第三方凉凉...

郭一璞 栗子 发自 凹非寺量子位 出品 | 公众号 QbitAIGitHub激动地宣布&#xff0c;终于支持CI/CD了。CI\CD&#xff0c;全称&#xff1a;持续集成 (Continuous Integration) &#xff0c;持续部署 (Continuous Deployment) &#xff0c;是开发流程的自动化利器&#xff0c;如今…

iOS开发③UIView

UILabel Lable的作用是显示不可编辑的文字。 属性检查器 Text&#xff1a;Label显示的文字Color&#xff1a;文字的颜色Font&#xff1a;字体和字号Alignment&#xff1a;文本的对齐方式Lines&#xff1a;设置Label中文本的行数&#xff0c;默认为1 Line Breaks&#xff1a;设置…

linux下的几种隐藏技术

0x00 前言 攻击者在获取服务器权限后&#xff0c;会通过一些技巧来隐藏自己的踪迹和后门文件&#xff0c;本文介绍Linux下的几种隐藏技术。 0x01 隐藏文件 Linux 下创建一个隐藏文件&#xff1a;touch .test.txt touch 命令可以创建一个文件&#xff0c;文件名前面加一个 点…

一支笔的AI之旅

乾明 发自 凹非寺 量子位 报道 | 公众号 QbitAI你知道地球上物种大爆发的时代吗&#xff1f;现在就很像。但不是生物物种&#xff0c;而是AI带来的一个又一个新硬件、新产品和新物种。一切正在被重新定义&#xff0c;小到一支笔&#xff0c;大到一家公司&#xff0c;再大到整个…

android上传项目到码云_上传代码到码云

对比 github 和码云&#xff0c;码云在不付费的前提下可以建立私有项目&#xff0c;于是上传了一份代码到码云。一、在码云上创建项目1.创建设置项目项目设置2、创建成功&#xff0c;复制地址创建成功二、打开终端 1.cd文件路径2.git init //初始化一个git 本地仓库此时会在本地…

新生赛(2) problem 2 丁磊养猪

Problem B Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 39 Accepted Submission(s) : 7 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description 丁磊同志是163网站CEO&#xff0c;…