2014-02-28 133 views
3

下圖 enter image description here如何降低R中

與此代碼生成的聚類和熱圖之間的差距

library(gplots) 
setwd("~/Desktop/"); 
data <- read.table(file='http://pastebin.com/raw.php?i=ZaGkPTGm', 
        header=TRUE, row.names=1) 

mat <- as.matrix(data[,-1]) 
z <- t(scale(t(mat))) 


# set custom distance and clustering functions 
hclustfunc <- function(x) hclust(x, method="complete") 
distfunc <- function(x) dist(x,method="maximum") 

# obtain the clusters 
fit <- hclustfunc(distfunc(z)) 
clusters <- cutree(fit, 5) 

# require(gplots) 
pdf(file='heatmap.pdf', height=50, width=90) 
heatmap.2(z, trace='none', dendrogram='row', Colv=F, scale='row', 
      hclust=hclustfunc, distfun=distfunc, col=greenred(256), symbreak=T, 
      margins=c(10,20), keysize=0.5, labRow=data$Gene.symbol, 
      lwid=c(1,0.05,1), lhei=c(0.03,1), lmat=rbind(c(5,0,4),c(3,1,2)), 
      RowSideColors=as.character(clusters)) 
dev.off() 

什麼,我做的是減少樹狀圖之間的差距熱圖的行邊顏色。 我該如何做到這一點?

唯一的要求是樹狀圖和紙張尺寸的尺寸必須保持原樣。

+0

你能供應dput的'的輸出(數據)'或'dput(頭(數據))'爲了使這可重複? – Thomas

+0

按照輸出(頭(數據))的要求輸出'http://pastebin.com/raw.php?i=7Z0rcAR9 – pdubois

回答

1

一種解決方案是,使其適合所述數據範圍全局調整x軸:

par(xaxs="i") 
heatmap.2(z, trace='none', dendrogram='row', Colv=F, scale='row', 
     hclust=hclustfunc, distfun=distfunc, col=greenred(256), symbreak=T, 
     margins=c(10,20), keysize=0.5, labRow=data$Gene.symbol, 
     lwid=c(1,0.05,1), lhei=c(0.03,1), lmat=rbind(c(5,0,4),c(3,1,2)), 
     RowSideColors=as.character(clusters))