2013-01-13 26 views
1

我使用以下代碼用於產生熱圖(從AvgByQ向量的):如何生成塊大小不均勻的熱圖?

library(gplots) 
x<-c(0, 5, 30, 80) 
y<-c(150, 2000, 2010, 3000) 
AvgByQ<-c(20.25, 13.02, 0.00, 0.00, 0.00, 0.00, 8.31, 14.66, 0.00) 
AvgByQMatrix <- matrix(AvgByQ, ncol=3, byrow=TRUE) 
heatmap.2(AvgByQMatrix, cellnote=AvgByQMatrix, notecol="black",col=redblue(256),key=TRUE, dendrogram = "none", trace="none") 

我怎樣才能改變塊大小,以匹配/分至X和Y矢量值? 此外,與縮放問題有些相關,任何想法爲什麼行順序(1,3,2)會搞砸了? 謝謝!

+0

我困惑你將如何擴展您的矩陣x和y的x, y是1x5的矢量,你會縮放3x3的矩陣嗎?當然我想念這裏的東西。 – agstudy

+0

它們之間的範圍,X(5,25,50)Y(1850,10,990) – user971956

+0

謝謝,實際上在這裏找到了我的答案http: //stackoverflow.com/questions/12040240/increasing-row-height-in-r-heatmap-function – user971956

回答

0

我認爲這可能對你有所幫助。下面的方法很適合我(雖然我只知道如何與image()功能做到這一點:?

#using image() function 
x<-c(0, 5, 30, 80, 1000) 
y<-c(150, 2000, 2010, 3000) 
grd <- expand.grid(x=x, y=y) 
z<-matrix(grd$x*2-grd$y*3, nrow=length(x), ncol=length(y), byrow=TRUE) 
image(x=x, y=y, z=z, col=rainbow(20)) 

#another option with z-scale 
source("image.scale.r") #http://menugget.blogspot.de/2011/08/adding-scale-to-image-plot.html 
x11(width=5, height=4) 
layout(matrix(1:2, nrow=1, ncol=2), widths=c(4,1), heights=4, respect=TRUE) 
layout.show(2) 
par(mar=c(4,4,1,1)) 
image(x=x, y=y, z=z, col=rainbow(20)) 
par(mar=c(4,0,1,4)) 
image.scale(z, col=rainbow(20), horiz=FALSE, xlab="", ylab="", xaxt="n", yaxt="n") 
axis(4) 
box() 

enter image description here