I'm using a ggdendrogram to plot a dendrogram, but I want to have the labels on the left to make the graph more intuitive. How do I do this? Thanks!!!
library(ggplot2)
library(ggdendro)
### Data
countries <- c("UK","AU","SA","CH")
distmatrix <- matrix(c(0.00, 0.16, 1.01, 0.97, 0.16, 0.00, 0.84, 0.79, 1.01, 0.84, 0.00, 1.49, 0.97, 0.79, 1.49, 0.00),
nrow=4,dimnames=list(countries, countries))
### Cluster
hc = hclust(as.dist(distmatrix), method = "ward")
### Plot
ggdendrogram(hc, rotate=TRUE, theme_dendro=FALSE)
The point is that the code
ggdendrogramwhenrotate=TRUEdoes this:But you don't want that
scale_y_reverse(.)to be done. So, one way is for you to do thecoord_flip()yourself.But, one obvious problem is that the
labelswould't justified properly. And you can't do much withinggdendrogram()function because it doesn't allow settinghjustandangleproperties externally.So, I'd suggest for your case, that you create the
ggplot()yourself by copying the lines from withinggdendrogramfunction.This gives:
Another way is for you to modify the
ggdendrogramfunction to your needs and re-compile it. I think it's much easier to do it this way and is quite what you want as well: