[英]ggplot: Heat map from 2D frequency histogram
my input data looks like that: 我的输入数据如下所示:
AA 36C 37T 38T
36C 17935 3349 16843
37T 3349 4 5690
38T 16843 5690 11
I would like to visualize the data in a way that I have nxn tiles and the colour of tile (0,0) would be based on the number for the contact 36C-36C (17935 in this case), tile (0,1) based on the number for the contact 36C-37T and so on. 我想以一种具有nxn个图块的方式可视化数据,并且图块(0,0)的颜色将基于触点36C-36C(在这种情况下为17935),图块(0,1)的数量根据触点36C-37T的数量等等。 I suppose
geom_tile
should do the job, but I don't know how to do it. 我想
geom_tile
应该完成这项工作,但是我不知道该怎么做。
When I read in the data I get 当我读数据时,我得到
data = read.table("test.tbl", header = T)
数据= read.table(“ test.tbl”,标头= T)
> str(data)
'data.frame': 3 obs. of 4 variables:
$ AA : Factor w/ 3 levels "36C","37T","38T": 1 2 3
$ X36C: int 17935 3349 16843
$ X37T: int 3349 4 5690
$ X38T: int 16843 5690 11
After that I don't know how to proceed and tell ggplot to plot the matrix. 之后,我不知道如何进行操作并告诉ggplot绘制矩阵。 Thanks for any help.
谢谢你的帮助。
Sorry, should have done more research before asking. 抱歉,在问之前应该做更多的研究。
It worked by melting the data frame. 它通过融合数据帧来工作。
> library(reshape2)
> melt(data)
Using AA as id variables
AA variable value
1 36C X36C 17935
2 37T X36C 3349
3 38T X36C 16843
4 36C X37T 3349
5 37T X37T 4
6 38T X37T 5690
7 36C X38T 16843
8 37T X38T 5690
9 38T X38T 11
ggplot(data_new, aes(x = variable, y = AA)) + geom_tile(aes(fill = value))
then provides the desired result. ggplot(data_new, aes(x = variable, y = AA)) + geom_tile(aes(fill = value))
然后提供所需的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.