我的以下代码:
library(gplots);
library(RColorBrewer);
dat <- read.table("http://pastebin.com/raw.php?i=wM7WxEvY",sep="\t",na.strings="NA",header=TRUE)
dat <- dat[complete.cases(dat),]
dat.log <- log2(dat);
# Clustering and distance function
hclustfunc <- function(x) hclust(x, method="ward")
distfunc <- function(x) dist(x,method="maximum")
# Here we cluster based on the Celltype (Column)
d <- distfunc(t(dat.log))
fit <- hclustfunc(d)
clusters <- cutree(fit, h=20)
nofclust.height <- length(unique(as.vector(clusters)));
# Colors setting
hmcols <- rev(redblue(256));
selcol <- colorRampPalette(brewer.pal(9,"Set1"))
clustcol.height = selcol(nofclust.height);
pdf(file="temp.pdf",width=30,height=40);
heatmap.2(as.matrix(dat.log),Colv=FALSE,lhei = c(0.25,4),ColSideColors=clustcol.height[clusters],density.info="none",scale="none",margin=c(10,10),col=hmcols,symkey=F,trace="none",dendrogram="none",keysize=1,hclust=hclustfunc,distfun=distfunc);
dev.off();
生成此图:
请注意,ColSideColors
太高。怎么才能缩短呢?
最佳答案
?heatmap.2
:可以通过为 lmat、lwid 和 指定适当的值来覆盖 RowSideColor
和 ColSideColor
的布局lhei。lmat
控制每个元素的相对位置,而lwid
控制列宽,lhei
控制行高。请参阅帮助页面layout 了解如何使用这些参数的详细信息。”
就您而言,您必须更改 lhei,请尝试 lhei=c(1,15)
关于r - 如何缩短heatmap.2()中ColSideColors的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20675242/