Domanda

How can I make it so R plots the dendrogram scale (so that the height of each dendrogram can be interpreted) along with the heatmap when calling NMF package aheatmap or heatmap.2? These dendrograms show the scale: http://gastonsanchez.com/blog/how-to/2012/10/03/Dendrograms.html This is the default behavior of doing plot(hclust(...)) and I'd like to emulate that but not sure how to do it via heatmap functions.

È stato utile?

Soluzione

The issue here is how heatmap.2 plots a dendrogram object. heatmap.2 uses the code plot(ddr, horiz = TRUE, axes = TRUE, yaxs = "i", leaflab = "none"), where ddr is the dendrogram. You want the axes argument to be FALSE. As a workaround, I created a modified version of the heatmap.2 function. See ?plot.dendrogram for more information.

x = matrix( rnorm(25), ncol=5 )
f = gplots:::heatmap.2

# Edit the appropriate lines of the heatmap.2 function
print(body(f)[[75]]) # The line to edit
# if (dendrogram %in% c("both", "row")) {
#   plot(ddr, horiz = TRUE, axes = FALSE, yaxs = "i", leaflab = "none")
# } else plot.new()
body(f)[[75]][[3]][[2]][[4]] = TRUE

print(body(f)[[77]])
# if (dendrogram %in% c("both", "column")) {
#   plot(ddc, axes = FALSE, xaxs = "i", leaflab = "none")
# } else plot.new()
body(f)[[77]][[3]][[2]][[3]] = TRUE

f(x)

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top