【SCI绘图】【热力图系列2 R】多特征相关性分析热力图指定聚类 R

2024-04-09 02:44

本文主要是介绍【SCI绘图】【热力图系列2 R】多特征相关性分析热力图指定聚类 R,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

SCI,CCF,EI及核心期刊绘图宝典,爆款持续更新,助力科研!

本期分享: 

【SCI绘图】【热力图系列2 R】多特征相关性分析热力图指定聚类 R

1.环境准备

library(gplots)
library(RColorBrewer)

2.数据读取

#########################################################
### reading in data and transform it to matrix format
#########################################################data <- read.csv("dataset.csv", comment.char="#")
rnames <- data[,1]                            # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)])  # transform column 2-5 into a matrix
rownames(mat_data) <- rnames                  # assign row names

3.绘图展示

#########################################################
### customizing and plotting heatmap
########################################################## creates a own color palette from red to green
my_palette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)# creates a 5 x 5 inch image
png("h3_categorizing.png",width = 5*300,        # 5 x 300 pixelsheight = 5*300,res = 300,            # 300 pixels per inchpointsize = 8)        # smaller font sizeheatmap.2(mat_data,cellnote = mat_data,  # same data set for cell labelsRowSideColors = c(    # grouping row-variables into differentrep("gray", 3),   # categories, Measurement 1-3: greenrep("blue", 3),    # Measurement 4-6: bluerep("black", 4)),    # Measurement 7-10: redmain = "Categories",  # heat map titlenotecol="black",      # change font color of cell labels to blackdensity.info="none",  # turns off density plot inside color legendtrace="none",         # turns off trace lines inside the heat mapmargins =c(12,9),     # widens margins around plotcol=my_palette,       # use on color palette defined earlier dendrogram="row",     # only draw a row dendrogramColv="NA")            # turn off column clustering# adding a color legend for the categories
par(lend = 1)           # square line ends  for the color legend
legend("topright",      # location of the legend on the heatmap plotlegend = c("category1", "category2", "category3"), # category labelscol = c("gray", "blue", "black"),  # color keylty = 1,            # line stylelwd = 10,           # line width)dev.off()

这篇关于【SCI绘图】【热力图系列2 R】多特征相关性分析热力图指定聚类 R的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/887002

相关文章

Spring事务中@Transactional注解不生效的原因分析与解决

《Spring事务中@Transactional注解不生效的原因分析与解决》在Spring框架中,@Transactional注解是管理数据库事务的核心方式,本文将深入分析事务自调用的底层原理,解释为... 目录1. 引言2. 事务自调用问题重现2.1 示例代码2.2 问题现象3. 为什么事务自调用会失效3

找不到Anaconda prompt终端的原因分析及解决方案

《找不到Anacondaprompt终端的原因分析及解决方案》因为anaconda还没有初始化,在安装anaconda的过程中,有一行是否要添加anaconda到菜单目录中,由于没有勾选,导致没有菜... 目录问题原因问http://www.chinasem.cn题解决安装了 Anaconda 却找不到 An

Spring定时任务只执行一次的原因分析与解决方案

《Spring定时任务只执行一次的原因分析与解决方案》在使用Spring的@Scheduled定时任务时,你是否遇到过任务只执行一次,后续不再触发的情况?这种情况可能由多种原因导致,如未启用调度、线程... 目录1. 问题背景2. Spring定时任务的基本用法3. 为什么定时任务只执行一次?3.1 未启用

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解

C++ 各种map特点对比分析

《C++各种map特点对比分析》文章比较了C++中不同类型的map(如std::map,std::unordered_map,std::multimap,std::unordered_multima... 目录特点比较C++ 示例代码 ​​​​​​代码解释特点比较1. std::map底层实现:基于红黑

Python实现合并与拆分多个PDF文档中的指定页

《Python实现合并与拆分多个PDF文档中的指定页》这篇文章主要为大家详细介绍了如何使用Python实现将多个PDF文档中的指定页合并生成新的PDF以及拆分PDF,感兴趣的小伙伴可以参考一下... 安装所需要的库pip install PyPDF2 -i https://pypi.tuna.tsingh

Spring、Spring Boot、Spring Cloud 的区别与联系分析

《Spring、SpringBoot、SpringCloud的区别与联系分析》Spring、SpringBoot和SpringCloud是Java开发中常用的框架,分别针对企业级应用开发、快速开... 目录1. Spring 框架2. Spring Boot3. Spring Cloud总结1. Sprin

Spring 中 BeanFactoryPostProcessor 的作用和示例源码分析

《Spring中BeanFactoryPostProcessor的作用和示例源码分析》Spring的BeanFactoryPostProcessor是容器初始化的扩展接口,允许在Bean实例化前... 目录一、概览1. 核心定位2. 核心功能详解3. 关键特性二、Spring 内置的 BeanFactory

MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析

《MyBatis-Plus中Service接口的lambdaUpdate用法及实例分析》本文将详细讲解MyBatis-Plus中的lambdaUpdate用法,并提供丰富的案例来帮助读者更好地理解和应... 目录深入探索MyBATis-Plus中Service接口的lambdaUpdate用法及示例案例背景

MyBatis-Plus中静态工具Db的多种用法及实例分析

《MyBatis-Plus中静态工具Db的多种用法及实例分析》本文将详细讲解MyBatis-Plus中静态工具Db的各种用法,并结合具体案例进行演示和说明,具有很好的参考价值,希望对大家有所帮助,如有... 目录MyBATis-Plus中静态工具Db的多种用法及实例案例背景使用静态工具Db进行数据库操作插入