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

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

本期分享:

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

1.环境准备

R 复制代码
library(gplots)
library(RColorBrewer)

2.数据读取

R 复制代码
#########################################################
### 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.绘图展示

R 复制代码
#########################################################
### 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 pixels
  height = 5*300,
  res = 300,            # 300 pixels per inch
  pointsize = 8)        # smaller font size

heatmap.2(mat_data,
  cellnote = mat_data,  # same data set for cell labels
  RowSideColors = c(    # grouping row-variables into different
     rep("gray", 3),   # categories, Measurement 1-3: green
     rep("blue", 3),    # Measurement 4-6: blue
     rep("black", 4)),    # Measurement 7-10: red
  main = "Categories",  # heat map title
  notecol="black",      # change font color of cell labels to black
  density.info="none",  # turns off density plot inside color legend
  trace="none",         # turns off trace lines inside the heat map
  margins =c(12,9),     # widens margins around plot
  col=my_palette,       # use on color palette defined earlier 
  dendrogram="row",     # only draw a row dendrogram
  Colv="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 plot
    legend = c("category1", "category2", "category3"), # category labels
    col = c("gray", "blue", "black"),  # color key
    lty = 1,            # line style
    lwd = 10,           # line width
   )

dev.off()
相关推荐
超皮小龙猫9 分钟前
c语言-1
c语言·开发语言
郝学胜-神的一滴1 小时前
完全二叉树与堆底层原理深度剖析 | 手写C++大顶堆实现
java·开发语言·数据结构·c++·python·算法
黄毛火烧雪下1 小时前
Java 基础笔记:文件、递归与字符编码
java·开发语言·笔记
swordbob1 小时前
CAP 定理:为什么不能同时实现 C、A、P?
开发语言·后端·spring
疯狂成瘾者1 小时前
Java 常用工具包 java.util
java·开发语言·windows
枫叶丹41 小时前
【HarmonyOS 6.0】MDM Kit 新特性:PC/2in1设备无锁屏密码重启自动解锁能力详解
开发语言·华为·harmonyos
ZHW_AI课题组2 小时前
Python 调用百度智能云 API 实现地址识别
开发语言·人工智能·python·机器学习·百度·数据挖掘
88号技师2 小时前
2026年2月一区SCI-交叉传播优化算法Propagation Alongside Crossover-附Matlab免费代码
开发语言·算法·数学建模·matlab·优化算法
A.零点2 小时前
【2个月 C 语言从入门到精通:零基础系统教程】第十二讲:深入了解指针(五)
c语言·开发语言·网络·笔记·visual studio
Biomamba生信基地2 小时前
NC | 单细胞分析揭示头颈部癌早期转移过程中潜在的免疫逃逸机制(R语言版本)
论文阅读·生物信息学·单细胞rna测序