我对少数几个因素进行了几千次观察,根据每个因素的最小值将这些因素转化为离散的 1/0 值,并将其绘制在 heatmap.2(红色=1,黑色=0)中。这绘制了 A+B+C+D 为 1、3 个因素的组合为 1、2 个因素的组合等的组合。我希望将这些组合的分数绘制在左侧垂直heatmap.2中的轴:
nentries=10000
ci=rainbow(nentries)
set.seed=1
mean=10
## Generate some data (4 factors)
i = data.frame(
a=round(abs(rnorm(nentries,mean-2))),
b=round(abs(rnorm(nentries,mean-1))),
c=round(abs(rnorm(nentries,mean+1))),
d=round(abs(rnorm(nentries,mean+2)))
)
minvalue = 10
# Discretise values to 1 or 0
m0 = matrix(as.numeric(i>minvalue),nrow=nrow(i))
# Remove rows with all zeros
m = m0[rowSums(m0)>0,]
# Reorder with 1,1,1,1 on top
ms =m[order(as.vector(m %*% matrix(2^((ncol(m)-1):0),ncol=1)), decreasing=TRUE),]
rowci = rainbow(nrow(ms))
colci = rainbow(ncol(ms))
heatmap(ms,
Rowv=NA,
labRow=" ",
keep.dendro = FALSE,
col=c("black","red"),
RowSideColors=rowci,
ColSideColors=colci,
)
RowSideColors 现在是具有 nrow(ms) 颜色的彩虹,而我希望拥有因子和图例的 1/0 组合。RowSideColors 旁边的类似:A+B+C+D 1%
、、等。B+C+D 10%
有任何想法吗?