如何为我在树状图中添加的一些彩色条添加标签?
下面的代码将显示我为瞄准任务所做的两次尝试,将值1链接到红色,将值0链接到彩色条的标签中的白色。
# replacing the graphic window parameter so the color bars would fit
par( oma = c(0,1,1,1), mgp = c(1,0.5,0), mar = c(10,2,2,2) )
# load necessary packages
library( squash )
library( dendextend )
# "initializatin"
data("mtcars")
myDend <- as.dendrogram(hclust(dist(mtcars)))
# creating the numeric & color matrix used for
# (attempted) labels & colors bars, respectively
myStatus <- cbind(mtcars$vs,mtcars$am)
myColors <- matrix(c("mintcream","firebrick3")[1 + myStatus],ncol = 2)
myColors <- matrix(c("mintcream","firebrick3")[1 + cbind(mtcars$vs,mtcars$am)],
ncol = 2)
# default function without trying to force the label to a particular design
plot(myDend)
cmap <- squash::makecmap( myStatus, n = 2,colFn = colorRampPalette(c("mintcream","firebrick3")))
vkey(cmap, "Status")
colored_bars(colors = myColors, dend = myDend, rowLabels = c("VS","AM"))
# >> attempt 1 << trying to force breaks to 0 and 1
plot(myDend)
cmap <- squash::makecmap( myStatus, n = 2,colFn = colorRampPalette(c("mintcream","firebrick3")), breaks = c(0,1))
vkey(cmap, "Status")
colored_bars(colors = myColors, dend = myDend, rowLabels = c("VS","AM"))
# >> attempt 2 << trying to force breaks to 0 and 1
plot(myDend)
cmap <- squash::makecmap( myStatus, n = 2,colFn = colorRampPalette(c("mintcream","firebrick3")))
vkey(cmap, "Status", skip = c(0.5))
colored_bars(colors = myColors, dend = myDend, rowLabels = c("VS","AM"))
生成的图分别存在以下问题:
用于彩色条的值是二进制的,但状态标签显示 4 个不同的值。
中断定义明确,但链接到它们的颜色是错误的
用于彩色条的值是二进制的,但状态标签显示 4 个不同的值(跳过没用)
这些地块是: