【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()
相关推荐
xidianhuihui32 分钟前
go install报错: should be v0 or v1, not v2问题解决
开发语言·后端·golang
架构师沉默35 分钟前
Java优雅使用Spring Boot+MQTT推送与订阅
java·开发语言·spring boot
DebugKitty1 小时前
C语言14-指针4-二维数组传参、指针数组传参、viod*指针
c语言·开发语言·算法·指针传参·void指针·数组指针传参
Bio Coder2 小时前
R语言中 read.table 和 read.delim 之间的区别
开发语言·r语言
LZQqqqqo3 小时前
C#_ArrayList动态数组
开发语言·windows·c#
睿思达DBA_WGX4 小时前
Python 程序设计讲义(27):字符串的用法——字符串的常用操作
开发语言·python
云天徽上4 小时前
【数据可视化-74】电信用户流失数据可视化分析:Python + Pyecharts 炫酷大屏(含完整的数据,代码)
开发语言·python·信息可视化·数据挖掘·数据分析·数据可视化·pyecharts
鲁Q同志4 小时前
java导入pdf(携带动态表格,图片,纯java不需要模板)
java·开发语言·pdf
_frank2224 小时前
kotlin使用mybatis plus lambdaQuery报错
开发语言·kotlin·mybatis
ZhuYuxi3334 小时前
【Kotlin】const 修饰的编译期常量
android·开发语言·kotlin