R语言绘制热图

1、初步绘图

rm(list=ls())#clear Global Environment
setwd('D:/Desktop/0000/code-main/热图')#设置工作路径#加载R包
library (pheatmap)
#读取数据
df <- read.table(file="data.txt",sep="\t",row.names = 1, header=T,check.names=FALSE)
#查看前3行
head(df)[1:5,]
####Z-score转换以保留数据的真实差异
df1 <-df[apply(df,1,var)!=0,]  ##去掉方差为0的行,也就是值全都一致的行
df_zscore <-as.data.frame(t(apply(df1,1,scale)))#标准化数据,获得Z-score
colnames(df_zscore)<- colnames(df)
###初步绘图
pheatmap(df_zscore,angle_col = "45", cellwidth=25, cellheight=8, treeheight_col = 15,filename = "heatmap.png")

2、设置颜色

rm(list=ls())#clear Global Environment
setwd('D:/Desktop/0000/code-main/热图')#设置工作路径#加载R包
library (pheatmap)
#读取数据
df <- read.table(file="data.txt",sep="\t",row.names = 1, header=T,check.names=FALSE)
#查看前3行
head(df)[1:5,]
####Z-score转换以保留数据的真实差异
df1 <-df[apply(df,1,var)!=0,]  ##去掉方差为0的行,也就是值全都一致的行
df_zscore <-as.data.frame(t(apply(df1,1,scale)))#标准化数据,获得Z-score
colnames(df_zscore)<- colnames(df)
#设置颜色
pheatmap(df_zscore,angle_col = "45", cellwidth=25, cellheight=8, treeheight_col = 15,color=colorRampPalette(c("#3952a2","black","#f5ea14"))(100),filename = "heatmap.png")

3、添加行注释信息

rm(list=ls())#clear Global Environment
setwd('D:/Desktop/0000/code-main/热图')#设置工作路径#加载R包
library (pheatmap)
#读取数据
df <- read.table(file="data.txt",sep="\t",row.names = 1, header=T,check.names=FALSE)
#查看前3行
head(df)[1:5,]
####Z-score转换以保留数据的真实差异
df1 <-df[apply(df,1,var)!=0,]  ##去掉方差为0的行,也就是值全都一致的行
df_zscore <-as.data.frame(t(apply(df1,1,scale)))#标准化数据,获得Z-score
colnames(df_zscore)<- colnames(df)#添加行注释信息
annotation_col<- data.frame( "Treatment" = c("Saline","Saline","Saline","Cocaine","Saline","LSD","LSD","LSD","LSD","Saline","Saline","Saline","MDMA","MDMA","MDMA","Ketamine","Ketamine","Ketamine","Ketamine","Ketamine"),"Batch" = c("1","1","1","1","2","1","2","3","2","1","2","2","2","1","2","1","3","3","3","3"),"Post_treatment" = c("48 h","2 wk","2 wk","48 h","48 h","48 h","2 wk","48 h","48 h","2 wk","48 h","2 wk","2 wk","2 wk","2 wk","2 wk","48 h","48 h","48 h","48 h"),"Critical_period" = c("Closed","Closed","Closed","Closed","Closed","Closed","Closed","Closed","Closed","Open","Open","Open","Open","Open","Open","Open","Open","Open","Open","Open"))#行注释矩阵
rownames(annotation_col) = colnames(df_zscore)
colors  <-  list("Treatment" = c(Saline = "#000000", Cocaine = "#575757",LSD = "#e79600",MDMA="#a42422",Ketamine="#c53a8e"), "Batch" = c( "1"= "#3953a3", "2" = "#ef4a4a", "3" = "#009848"),"Post_treatment" = c("48 h"="#64838c","2 wk"="#2c3a3e"),"Critical_period" = c(Closed="#94c83d",Open="#4e2469"))
pheatmap(df_zscore,angle_col = "45", cellwidth=25, cellheight=8, treeheight_col = 15,color=colorRampPalette(c("#3952a2","black","#f5ea14"))(100),annotation_col = annotation_col,annotation_colors = colors,show_colnames = F,filename = "heatmap.png")

4、美化(通过调节细节参数以及结合AI进行美化)

rm(list=ls())#clear Global Environment
setwd('D:/Desktop/0000/code-main/热图')#设置工作路径#加载R包
library (pheatmap)
#读取数据
df <- read.table(file="data.txt",sep="\t",row.names = 1, header=T,check.names=FALSE)
#查看前3行
head(df)[1:5,]
####Z-score转换以保留数据的真实差异
df1 <-df[apply(df,1,var)!=0,]  ##去掉方差为0的行,也就是值全都一致的行
df_zscore <-as.data.frame(t(apply(df1,1,scale)))#标准化数据,获得Z-score
colnames(df_zscore)<- colnames(df)#添加行注释信息
annotation_col<- data.frame( "Treatment" = c("Saline","Saline","Saline","Cocaine","Saline","LSD","LSD","LSD","LSD","Saline","Saline","Saline","MDMA","MDMA","MDMA","Ketamine","Ketamine","Ketamine","Ketamine","Ketamine"),"Batch" = c("1","1","1","1","2","1","2","3","2","1","2","2","2","1","2","1","3","3","3","3"),"Post_treatment" = c("48 h","2 wk","2 wk","48 h","48 h","48 h","2 wk","48 h","48 h","2 wk","48 h","2 wk","2 wk","2 wk","2 wk","2 wk","48 h","48 h","48 h","48 h"),"Critical_period" = c("Closed","Closed","Closed","Closed","Closed","Closed","Closed","Closed","Closed","Open","Open","Open","Open","Open","Open","Open","Open","Open","Open","Open"))#行注释矩阵
rownames(annotation_col) = colnames(df_zscore)
colors  <-  list("Treatment" = c(Saline = "#000000", Cocaine = "#575757",LSD = "#e79600",MDMA="#a42422",Ketamine="#c53a8e"), "Batch" = c( "1"= "#3953a3", "2" = "#ef4a4a", "3" = "#009848"),"Post_treatment" = c("48 h"="#64838c","2 wk"="#2c3a3e"),"Critical_period" = c(Closed="#94c83d",Open="#4e2469"))
###美化
pheatmap(df_zscore,angle_col = "45", cellwidth=25, cellheight=8, treeheight_col = 15,color=colorRampPalette(c("#3952a2","black","#f5ea14"))(100),annotation_col = annotation_col,annotation_colors = colors,show_colnames = F,fontsize_row=9, fontsize=12,labels_row = as.expression(lapply(rownames(df_zscore),function(x) bquote(italic(.(x))))),#行名斜体filename = "heatmap.png")

5、数据

热图.zip - 蓝奏云

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

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

idea启动缓慢解决办法

idea启动缓慢解决办法 文章目录 idea启动缓慢解决办法前言一、修改内存大小二、虚拟机运行大小三、插件禁用1、安卓相关2、构建工具3、Code Coverage 代码覆盖率4、数据库5、部署工具6、html和xml7、ide settings8、JavaScript框架和工具9、jvm框架10、Keymap快捷键映射11、kot…

ARM Linux DIY(十三)Qt5 移植

前言 板子带有屏幕&#xff0c;那当然要设计一下 GUI&#xff0c;对 Qt5 比较熟悉&#xff0c;那就移植它吧。 移植 Qt5 buildroot 使能 Qt5&#xff0c;这里我们只开启核心功能 gui module --> widgets module 编译 $ make ODIY_V3S/ qt5base编译报错&#xff1a;找不…

【项目经验】:elementui表格中数字汉字排序问题及字符串方法localeCompare()

一.需求 表格中数字汉字排序&#xff0c;数字按大小排列&#xff0c;汉字按拼音首字母&#xff08;A-Z&#xff09;排序。 二.用到的方法 第一步&#xff1a;把el-table-column上加上sortable"custom" <el-table-column prop"date" label"序号…

Ubuntu下高效Vim的搭建(离线版)

软件界面 可以看到界面下方有一些常用提示信息&#xff1a;文件路径、format、文件类型、光标所在的坐标(x,y)、进度条(百分比)、日期时间 会提示已定义的变量名词(快速补全) 搭建方法 下载资源文件 把Vim 和 .vimrc 拷贝到家目录下&#xff0c;并执行tar -xvf Vim 即可。 …

外星人入侵游戏-(创新版)

&#x1f308;write in front&#x1f308; &#x1f9f8;大家好&#xff0c;我是Aileen&#x1f9f8;.希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流. &#x1f194;本文由Aileen_0v0&#x1f9f8; 原创 CSDN首发&#x1f412; 如…

『PyQt5-Qt Designer篇』| 09 Qt Designer中分割线和间隔如何使用?

09 Qt Designer中分割线和间隔如何使用? 1 间隔1.1 水平间隔1.2 垂直间隔2 分割线2.1 水平线2.2 垂直线3 保存并执行1 间隔 间隔有水平间隔和垂直间隔: 1.1 水平间隔 拖动4个按钮,并设置为水平布局: 在第一个按钮的右边添加一个水平间隔: 设置其sizeType为Fixed,宽度为20…

ipv6笔记及总结

1、路由器请求消息Router Solicitation和路由器通告Router Advertisement消息主要用于无状态地址的情况下&#xff0c;有状态的情况使用的是dhcpv6 server分配&#xff08;例如&#xff1a;IPv6地址以及其他信息&#xff08;DNS、域名等&#xff09;&#xff09;。 2、关于IPv…

Learn Prompt-Midjourney 图片生成

简介 随着 ChatGPT 的爆火&#xff0c;越来越多的人开始关注并尝试 AI 相关的应用。而图片生成就是其中一个备受瞩目的领域。目前已经有许多图像生成工具&#xff0c;如 Midjourney&#xff0c;Stable Diffusion&#xff0c;DALL-E&#xff0c;Firefly等。本课程主要是以 Midj…

Multitor:一款带有负载均衡功能的多Tor实例创建工具

关于Multitor Multitor是一款带有负载均衡功能的多Tor实例创建工具&#xff0c;Multitor的主要目的是以最快的速度完成大量Tor进程的初始化&#xff0c;并将大量实例应用到我们日常使用的程序中&#xff0c;例如Web浏览器和聊天工具等等。除此之外&#xff0c;在该工具的帮助下…

堆内存与栈内存

文章目录 1. 栈内存2. 堆内存3. 区别和联系参考资料 1. 栈内存 栈内存是为线程留出的临时空间 每个线程都有一个固定大小的栈空间&#xff0c;而且栈空间存储的数据只能由当前线程访问&#xff0c;所以它是线程安全的。栈空间的分配和回收是由系统来做的&#xff0c;我们不需…

【微信小程序】外卖点餐效果展示

概述 外卖点餐效果展示&#xff0c;左右布局&#xff0c;快速点餐&#xff0c;商家信息展示等...程序是模仿人家的&#xff0c;所以界面没做什么调整&#xff0c;功能是没啥问题&#xff0c;可以正常使用... 详细 直接看效果图&#xff1a; 可以把这个点餐这个功能分为5部分…

【Vue】快速入门案例与工作流程的讲解

&#x1f389;&#x1f389;欢迎来到我的CSDN主页&#xff01;&#x1f389;&#x1f389; &#x1f3c5;我是Java方文山&#xff0c;一个在CSDN分享笔记的博主。&#x1f4da;&#x1f4da; &#x1f31f;在这里&#xff0c;我要推荐给大家我的专栏《Vue快速入门》。&#x1f…