My question is related to Andrie's answer to my earlier question. My question is whether is this possible to display the variable labels and car label under the corresponding segments of the dendrogram?
library(ggplot2)
library(ggdendro)
data(mtcars)
x <- as.matrix(scale(mtcars))
dd.row <- as.dendrogram(hclust(dist(t(x))))
ddata_x <- dendro_data(dd.row)
p2 <- ggplot(segment(ddata_x)) +
geom_segment(aes(x=x0, y=y0, xend=x1, yend=y1))
print(p2)
Make sure you have version 0.0-7 of
ggdendro
and then use the convenience functionggdendrogram
:If you want full control over how the labels are displayed, you can extract and manipulate these from
ddata_x
using either:To add to your plot:
You can find more information in the vignette,
vignette("ggdendro")