Hi there,
I'm trying to figure out a heatmap with gene expression under 3 different conditions. Also I want to add a dendrogram with the clusterization of those genes. These are the commands I'm using in ggplot2 to do the heatmap:
data_r <- read.table("gene_table.txt", sep="\t", header=TRUE, row.names=1)
data <- data_r[order(data_r$cond1, data_r$cond2, data_r$cond3),] # Order columns highest to lowest
data$gene <- row.names(data)
data$gene <- with(data, factor(gene, levels=gene, ordered=TRUE))
melt_data <- melt(data, id.vars="gene")
ggplot(melt_data, aes(x=variable, y=gene)) + geom_tile(aes(fill=value)) + scale_fill_gradient(low = "yellow",high = "blue")
Using the previous commands, I get a heatmap with the highest values on the top. The problem is that when I try to figure out a dendrogram, the heatmap is reordered:
x <- as.matrix(data)
dd.col <- as.dendrogram(hclust(method="average",dist((x),method = "euclidean")))
col.ord <- order.dendrogram(dd.col)
xx <- (data)[col.ord,]
xx_names <- attr(xx, "dimnames")
df <- as.data.frame(xx)
df$gene <- row.names(df)
df$gene <- with(df, factor(gene, levels=gene, ordered=TRUE))
mdf <- melt(df, id.vars="gene")
ddata_y <- dendro_data(dd.col)
When I figure out the heatmap with the dendrogram, the heatmap is reordered, I think due to xx <- (data)[col.ord,] command. My question is, there is anyway to produce the dendrogram without reordering the heatmap?
Thanks in advance,
The whole point of a dendrogram is to reorder things by similarity. The correct solution is to either keep things reordered or don't use a dendrogram to begin with.
Thanks Devon, I know that the goal of a dendrogram is to reorder things but, if I have "my own" order, it is possible to create a dendro without reordering?(even it makes no sense...) Thanks!
I've never looked, but even if so the result could be a mess of lines.
Thanks a lot Devon ;)