Folded strip with hierarchical clustering (dendrogram)

I'm trying to get something like this, but unfortunately I couldn't find a package that could allow me to plot a stacked stroke graph with a dendrogram like below:

dendrogram

Does anyone know how to do this?

+3


source to share


1 answer


First hit back - but it will take more work to make it really work. In particular, you need to be more careful about the location of the elements (as well as their order).

# library
library(ggplot2)

# create a dataset
specie=c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition=rep(c("normal" , "stress" , "Nitrogen") , 4)
value=abs(rnorm(12 , 0 , 15))
data=data.frame(specie,condition,value)


dend <- as.dendrogram(hclust(dist(with(data, tapply(value, specie, mean)))))

data$specie <- factor(data$specie, levels = labels(dend))

# Stacked Percent
library(dendextend)
p1 <- ggplot(dend, horiz = T) 
p2 <- ggplot(data, aes(fill=condition, y=value, x=specie)) + 
    geom_bar( stat="identity", position="fill") + coord_flip()

library(cowplot)
plot_grid(p1, p2, align = "h")

      



enter image description here

+1


source







All Articles