【问题标题】:How can I combine several heatmaps using R in a signal figure如何在信号图中使用 R 组合多个热图
【发布时间】:2014-08-31 04:20:17
【问题描述】:

我已经使用函数 pheatmap 创建了 36 个热图,我只想将它们显示在一个图中。我曾尝试使用函数 par(),但它不起作用,我不知道为什么。有人可以告诉我该怎么做吗?非常感谢你。这是我的代码:

require(graphics);require(grDevices);library("pheatmap", lib.loc="D:/Program Files/R/R-3.1.1/library");library(gplots)
filenames<-list.files("D:/Project/bladder cancer/heatmap0829/heatmap/"); # detect all of the files in the fold
filename2<-strtrim(filenames,nchar(filenames)-4); # all of the filenames without extension names
par(mfrow=c(18,2)) #divide the graphics windows into a 18x2 matrix
for(i in 1:length(filename2)){
rt<-read.table(paste("D:/Project/bladder cancer/heatmap0829/heatmap/",filenames[i],sep = ""), header = T, sep = '\t') # Import the data with the ith file name
size=dim(rt) # the dimensional of the datafram
 cw=400/size[1] #the width of the cell in the heatmap
rt<-log10(rt)
x <- t(data.matrix(rt))
pheatmap(x,color=greenred(256),main=filename2[i],cluster_rows = F, cluster_cols = T,cellwidth = cw, cellheight = 60,border_color =F,fontsize = 8,fontsize_col = 15)}

这是一个数据集

ScaBER  5637
1   1.010001e+02
1.341186e+00    2.505067e+01
1.669456e+01    8.834190e+01
7.141351e+00    3.897474e+01
1.585592e+04    5.858210e+04
1   3.137979e+01
1.498863e+01    7.694948e+01
1.115443e+02    3.642917e+02
1.157677e+01    5.036716e+01
4.926492e+02    8.642784e+03
3.047117e+00    1.872154e+01

我有 36 个这样的 txt 文件,但我不能把它们都放在这里 “ScaBER 5637”是这个数据集的列名

【问题讨论】:

  • 大多数热图函数会覆盖通常的 par() 设置。您应该使用更原始的函数,例如image,或者包含数据并更清楚地说明您想要的内容。
  • 非常感谢您的宝贵回复,我在代码后添加了一组数据。
  • 热图或图像的输入可以是矩阵或具有指定 x 和 y 向量的 z 向量。你还没有描述你期望看到的那个小的两列数据示例。

标签: r par pheatmap


【解决方案1】:

查看之前的回答:Histogram, error: Error in plot.new() : figure margins too large

par(mfcol=c(3,12), oma=c(1,1,0,0), mar=c(1,1,1,0), tcl=-0.1, mgp=c(0,0,0))


for(i in 1:36){

  plot(runif(2), runif(2), type="l")

}

dev.off()

【讨论】:

  • 谢谢你的建议,但它不起作用,也许热图和其他的有什么不同
猜你喜欢
  • 2013-07-22
  • 2019-02-08
  • 2021-09-29
  • 2015-06-08
  • 1970-01-01
  • 2022-11-28
  • 1970-01-01
  • 2020-07-23
  • 1970-01-01
相关资源
最近更新 更多