R语言绘制热图

news2024/11/18 23:31:51

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.coloradmin.cn/o/1018054.html

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

相关文章

STM32WB55开发(5)----调整射频功率

STM32WB55开发----5.调整射频功率 概述硬件准备视频教学样品申请选择芯片型号配置时钟源配置时钟树RTC时钟配置查看开启STM32_WPAN条件配置HSEM配置IPCC配置RTC启动RF开启蓝牙开启串口调试配置蓝牙参数设置工程信息工程文件设置Keil工程配置代码配置射频功率ACI_HAL_SET_TX_POW…

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

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

docker总结

Docker实用篇 0.学习目标 1.初识Docker 1.1.什么是Docker 微服务虽然具备各种各样的优势&#xff0c;但服务的拆分通用给部署带来了很大的麻烦。 分布式系统中&#xff0c;依赖的组件非常多&#xff0c;不同组件之间部署时往往会产生一些冲突。在数百上千台服务中重复部署…

SkyWalking9.5.0安装与SpringBoot性能链路监控

文章目录 1、下载安装1.1、安装Elasticsearch存储1.2、安装SkyWalking服务器端 2、监控微服务2.1、监控Spring Boot微服务2.1、监控Spring Cloud Gateway网关 Skywalking是分布式系统的应用程序性能监视工具&#xff0c;专为微服务&#xff0c;云原生架构和基于容器&#xff08…

Windows系统版本下载

1. msdn itellyou&#xff1a;MSDN, 我告诉你 - 做一个安静的工具站 (itellyou.cn) 2. MSDN系统库&#xff0d;致力于原版windows生态服务 (xitongku.com)

苹果电脑Mac系统运行若依框架 RuoYi前后端分离版

苹果电脑Mac系统运行若依框架 RuoYi前后端分离版 若依官网 若依官网 http://doc.ruoyi.vip/ruoyi-vue/ 若依的代码和文档都在里面 demo下载下来后还要下载安装redis,启动redis 一、下载安装redis 在终端输入&#xff1a; brew install redis安装过程将自动为我们安装最新版本…

Promise的链式调用

catch方法 .catch(onRejected) .then(null, onRejected) 链式调用 then方法必定会返回一个新的Promise 可理解为后续处理也是一个任务 新任务的状态取决于后续处理&#xff1a; 若没有相关的后续处理&#xff0c;新任务的状态和前任务一致&#xff0c;数据为前任务的数据 …

K8s的ingress-nginx配置https

文章目录 一、自签证书&&创建ingress规则test-ingress-https.yaml 二、测试https访问 一、自签证书&&创建ingress规则 ## ingress配置https访问&#xff0c;这里使用自签证书实现https访问openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyo…

自动化测试岗位之百度测开面试题分享

1、java常用的异常处理机制&#xff1f; Java常用的异常处理机制有以下几种&#xff1a; 1&#xff09;try-catch-finally 语句&#xff1a;用于捕获和处理异常。将可能抛出异常的代码放在try块中&#xff0c;然后在catch块中处理异常。无论是否发生异常&#xff0c;finally块…

千巡翼X1 让航测无人机更小更轻更高效

利用无人机进行航空摄影测量&#xff0c;已成为测绘外业生产的主要方式&#xff0c;不仅方便快捷&#xff0c;更能全面准确获得成果。近年来&#xff0c;凭借快速高效、机动灵活、安全可靠、低成本等诸多优势&#xff0c;小型多旋翼无人机逐渐成为一些航测项目作业的新利器。 千…

SpringBoot启动方式

SpringBoot启动方式 springboot的启动经过了一些一系列的处理&#xff0c;我们先看看整体过程的流程图 SpringBoot的启动方式 <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><…

一文读懂最新的A股交易手续费,建议收藏

为了活跃资本市场&#xff0c;最近政策密集出台&#xff0c;印花税下降50%&#xff0c;交易经手费下降30%。 财政部、税务总局&#xff1a;为活跃资本市场、提振投资者信心&#xff0c;自2023年8月28日起&#xff0c;证券交易印花税实施减半征收 上交所发布《关于调整股票交易…

【C++初阶】C++STL详解(四)—— vector的模拟实现

​ ​&#x1f4dd;个人主页&#xff1a;Sherry的成长之路 &#x1f3e0;学习社区&#xff1a;Sherry的成长之路&#xff08;个人社区&#xff09; &#x1f4d6;专栏链接&#xff1a;C初阶 &#x1f3af;长路漫漫浩浩&#xff0c;万事皆有期待 【C初阶】CSTL详解&#xff08;三…

day22集合01

1.Collection集合 1.1数组和集合的区别【理解】 相同点 都是容器,可以存储多个数据 不同点 数组的长度是不可变的,集合的长度是可变的 数组可以存基本数据类型和引用数据类型 集合只能存引用数据类型,如果要存基本数据类型,需要存对应的包装类 1.2集合类体系结构【理解】…

详谈操作系统中的内核态和用户态

不知道大家有没有思考过这样一个问题:什么是处理器&#xff08;CPU&#xff09;的状态&#xff1f;&#x1f914; 其实CPU和人一样,没有执行程序的时候,是没有什么状态的,当它执行的程序是用户程序的时候就叫用户态&#xff0c;当执行的程序是操作系统的代码时就叫系统态或者内…

C++---继承

继承 前言继承的概念及定义继承的概念继承定义继承关系和访问限定符 基类和派生类对象赋值转换继承中的作用域派生类的默认成员函数继承与友元继承与静态成员**多重继承**多继承下的类作用域菱形继承虚继承使用虚基类 支持向基类的常规类型转换 前言 在需要写Father类和Mother…

嵌入式Linux驱动开发(I2C专题)(五)

I2C系统驱动程序模型 参考资料&#xff1a; Linux内核文档: Documentation\i2c\instantiating-devices.rstDocumentation\i2c\writing-clients.rst Linux内核驱动程序示例: drivers/eeprom/at24.c 1. I2C驱动程序的层次 I2C Core就是I2C核心层&#xff0c;它的作用&#xf…

20230916在WIN10的资源管理器里关闭最右边的预览窗口

20230916在WIN10的资源管理器里关闭最右边的预览窗口 百度搜索&#xff1a;WIN10 干掉预览模式 https://zhidao.baidu.com/question/1807564480928861867.html win10计算机预览窗口怎么关  我来答 首页 用户 合伙人 商城 法律 手机答题 我的 win10计算机预览窗口怎么关  …

知识库管理工具哪个好?我建议你可以试一下这个!

对于很多企业/用户来说&#xff0c;在职业成长和个人发展的过程中&#xff0c;是需要借助知识库管理工具来进行知识内容沉淀的。 随着工具市场的发展&#xff0c;各种知识库管理工具层出不穷&#xff0c;今天我就结合数据安全、知识管理体系、简单实用三个方面出发&#xff0c;…

flutter聊天界面-TextField输入框buildTextSpan实现@功能展示高亮功能

flutter聊天界面-TextField输入框buildTextSpan实现功能展示高亮功能 最近有位朋友讨论的时候&#xff0c;提到了输入框的高亮展示。在flutter TextField中需要插入特殊样式的标签&#xff0c;比如&#xff1a;“请 张三 回答一下”&#xff0c;这一串字符在TextField中输入&a…