plot(dend, horiz = TRUE)
, gives us a dendrogram tree plot
with the tips turned right. The current function enables the creation of
the same tree, but with the tips turned left. The main challange in doing this
is finding the distance of the labels from the leaves tips - which is solved
with this function.
plot_horiz.dendrogram(x, type = c("rectangle", "triangle"), center = FALSE, edge.root = is.leaf(x) || !is.null(attr(x, "edgetext")), dLeaf = NULL, horiz = TRUE, xaxt = "n", yaxt = "s", xlim = NULL, ylim = NULL, nodePar = NULL, edgePar = list(), leaflab = c("perpendicular", "textlike", "none"), side = TRUE, text_pos = 2, ...)
## Not run:
# dend <- USArrests[1:10,] %>% dist %>% hclust %>% as.dendrogram
#
# par(mfrow =c(1,2), mar = rep(6,4))
# plot_horiz.dendrogram(dend, side=FALSE)
# plot_horiz.dendrogram(dend, side=TRUE)
# # plot_horiz.dendrogram(dend, side=TRUE, dLeaf= 0)
# # plot_horiz.dendrogram(dend, side=TRUE, nodePar = list(pos = 1))
# # sadly, lab.pos is not implemented yet,
# ## so the labels can not be right aligned...
#
#
# plot_horiz.dendrogram(dend, side=F)
# plot_horiz.dendrogram(dend, side=TRUE, dLeaf=0, xlim = c(100,-10)) # bad
# plot_horiz.dendrogram(dend, side=TRUE, text_offset = 0)
# plot_horiz.dendrogram(dend, side=TRUE, text_offset = 0,text_pos=4)
#
# ## End(Not run)
Run the code above in your browser using DataLab