我正在尝试在R中制作一个热图,其中的标签文本是彩色的(以指示数据点来自哪个组)。
我目前使用的是heatmap.2,但我很乐意使用另一个包。
heatmap.2(data.matrix(data),trace = 'none', dendrogram='none',ColSideColors=col)这个调用为我提供了沿着标签的彩色条(ColSideColors),但我想让标签本身着色。
非常感谢!
发布于 2012-11-03 15:35:38
您将需要创建一个包含col.axis参数的新函数。下面是要使用的函数行:
# there were four long pages of code before this section:
axis(1, 1:nc, labels = labCol, las = 2, line = -0.5, tick = 0, # original line
col.axis="green", # added argument
cex.axis = cexCol)
if (!is.null(xlab))
mtext(xlab, side = 1, line = margins[1] - 1.25)
axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0, # original line
col.axis="green", # added argument
cex.axis = cexRow)发布于 2013-03-28 13:40:45
我最近也遇到了同样的问题,最终我用mtext替换了原来的axis。前面的答案显示了用于绘制标签的axis语句。但是,col.axis只能指定一种颜色。为了启用矢量颜色,
# axis(1, 1:nc, labels = labCol, las = 2, line = -0.5, tick = 0,
# cex.axis = cexCol )
mtext(side = 1, text = labCol, at = 1:nc, las = 2, line = 0.5,col = ClabColor, cex = cexCol)
# axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0,
# cex.axis = cexRow )
mtext(side = 4, text = labRow, at = iy, las = 2, line = 0.5,col = RlabColor, cex = cexCol)此外,请记住在函数ClabColor = "black", RlabColor = "black"中再添加两个参数。默认颜色为黑色。
另一件需要注意的事情是,矢量颜色应该遵循标签的顺序,这些标签在计算树状图时会被排列
发布于 2014-01-29 12:18:35
由于缺少评论权限,我无法回复lwz0203,但他们的代码并不十分完整。您需要添加以下行:
if(is.vector(RlabColor)) {
RlabColor=RlabColor[rowInd]
}(对于ClabColor也是如此)
if(is.vector(ClabColor)) {
ClabColor=ClabColor[colInd]
}在代码中的某个点,或者当您使用颜色矢量时,您将获得与标签不匹配的颜色。矢量labRow或labCol中的文本已经使用代码进行了重新排序:
if (is.null(labRow))
labRow <- if (is.null(rownames(x)))
(1:nr)[rowInd]
else rownames(x)
else labRow <- labRow[rowInd] 因此,我在同一位置添加了RlabColor和ClabColor的重新排序。
https://stackoverflow.com/questions/13206335
复制相似问题