R中带有heatmap.2的热图 [英] heat maps in R with heatmap.2

查看:167
本文介绍了R中带有heatmap.2的热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在R中创建一个热图.我尝试使用heatmap.2命令.

I am trying to create a heatmap in R. I have tried using the heatmap.2 command.

我的数据由x和y列以及一个点的相关相对频率(频率除以总频率)组成

My data consists of x, and y columns and associated relative frequency of a point(frequency divided by the total frequency)

在大多数地方为零频率,在其他地方为相对小频率.我将数据转换为矩阵,因为这似乎是heatmap命令想要的,并试图删除x和y坐标.

with zero frequency in most places and a small relative frequency in others. I have converted my data to a matrix since this seems what the heatmap command wants and attempted to remove the x and y-coordinates.

BB <- matrix(as.matrix(surfacerevfreq1[, 3]),  ncol = 35, byrow = T)

我看到有两个问题,没有列出所有的x和y坐标.即x坐标从1开始到35,而y坐标从11开始到30.我考虑过在数据集的开头插入零,以便y轴上从1到10的每个点都有一个值.但是,我不确定这是否是最好的主意.

There are two problems as I see it, not all x and y -coordinates are listed. i.e. the x-coordinate starts at 1 and goes to 35 whereas the y-coordinate starts at 11 and goes to 30. The heatmap function does not seem to like this. I have thought over inserting zeros at the beggining of the data set so that each point from 1- 10 on the y-axis had a value. However, I am not sure if this is the best idea.

所以我想我的问题是:如何格式化数据以便可以从该数据获得有效的热图?我应该补充一点,如果可能的话,我也希望在x和y刻度上显示数字.出于此目的,它以图形方式显示与每个点相关的相对频率.

So I suppose my question is: how do I format my data in such a way that I can a valid heatmap from this data? I should add that I want the numbers on my x and y-scale displayed also if possible. Since the purpose it to graphically show the relative frequency associated with each point.

谢谢.

这是我的数据的一个子集,以便您可以以矩阵形式查看它的样子

here is a subset of my data so that you can see what it looks like in matrix form

    col1         col2         col3         col4         col5         col6            col7         col8         col9        col10        col11        col12 
0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000    0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 
   col13        col14        col15        col16        col17         col18            col19        col20        col21        col22        col23        col24 
0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000  0.0000000000 0.0000000000 0.0000000000 0.0005017561 0.0005017561 0.0000000000 
   col25        col26        col27        col28        col29            col30            col31        col32        col33        col34        col35 
0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000      0.0000000000 0.0000000000 0.0000000000 0.0000000000 0.0000000000 

这是我正在使用的heatmap命令:

and here is the heatmap command that I am using:

hU <- heatmap.2(xx, Rowv=FALSE, symm=TRUE,  trace="none", density.info="none",   dendrogram="none")

推荐答案

考虑您的3列数据存储在data [x,y,q]中

Try this, considering your 3 columns data is stored in data[x, y, q]

a = matrix(0, nrow = 30 - 10, ncol = 35)
rownames(a) = 11:30
apply(data, 1, function(x) a[x[2] - 10, x[1]] <<- x[3])
heatmap.2(a, Rowv=FALSE, symm=TRUE,  trace="none", density.info="none", 
          dendrogram="none", xlab="X", ylab="Y")

这篇关于R中带有heatmap.2的热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆