Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plot_horiz.dendrogram

Plotting a left-tip-adjusted horizontal dendrogram


Description

The default 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.

Usage

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,
  ...
)

Arguments

x

tree object (dendrogram)

type

a character vector with either "rectangle" or "triangle" (passed to plot.dendrogram)

center

logical; if TRUE, nodes are plotted centered with respect to the leaves in the branch. Otherwise (default), plot them in the middle of all direct child nodes.

edge.root

logical; if true, draw an edge to the root node.

dLeaf

a number specifying the distance in user coordinates between the tip of a leaf and its label. If NULL as per default, 3/4 of a letter width is used.

horiz

logical indicating if the dendrogram should be drawn horizontally or not. In this function it MUST be TRUE!

xaxt

graphical parameters, or arguments for other methods.

yaxt

graphical parameters, or arguments for other methods.

xlim

(NULL) optional x- and y-limits of the plot, passed to plot.default. The defaults for these show the full dendrogram.

ylim

(NULL) optional x- and y-limits of the plot, passed to plot.default. The defaults for these show the full dendrogram.

nodePar

NULL.

edgePar

list()

leaflab

c("perpendicular", "textlike", "none")

side

logical (TRUE). Should the tips of the drawn tree be facing the left side. This is the important feature of this function.

text_pos

integer from either 1 to 4 (2). Two relevant values are 2 and 4. 2 (default) means that the labels are alligned to the tips of the tree leaves. 4 will have the labels allign to the left, making them look like they were when the tree was on the left side (with leaves tips facing to the right).

...

passed to plot.

Value

The invisiable dLeaf value.

Source

This function is based on replicating plot.dendrogram. In fact, I'd be happy if in the future, some tweaks could be make to plot.dendrogram, so that it would replace the need for this function.

See Also

Examples

## 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)

dendextend

Extending 'dendrogram' Functionality in R

v1.15.1
GPL-2 | GPL-3
Authors
Tal Galili [aut, cre, cph] (https://www.r-statistics.com), Yoav Benjamini [ths], Gavin Simpson [ctb], Gregory Jefferis [aut, ctb] (imported code from his dendroextras package), Marco Gallotta [ctb] (a.k.a: marcog), Johan Renaudie [ctb] (https://github.com/plannapus), The R Core Team [ctb] (Thanks for the Infastructure, and code in the examples), Kurt Hornik [ctb], Uwe Ligges [ctb], Andrej-Nikolai Spiess [ctb], Steve Horvath [ctb], Peter Langfelder [ctb], skullkey [ctb], Mark Van Der Loo [ctb] (https://github.com/markvanderloo d3dendrogram), Andrie de Vries [ctb] (ggdendro author), Zuguang Gu [ctb] (circlize author), Cath [ctb] (https://github.com/CathG), John Ma [ctb] (https://github.com/JohnMCMa), Krzysiek G [ctb] (https://github.com/storaged), Manuela Hummel [ctb] (https://github.com/hummelma), Chase Clark [ctb] (https://github.com/chasemc), Lucas Graybuck [ctb] (https://github.com/hypercompetent), jdetribol [ctb] (https://github.com/jdetribol), Ben Ho [ctb] (https://github.com/SplitInf), Samuel Perreault [ctb] (https://github.com/samperochkin), Christian Hennig [ctb] (http://www.homepages.ucl.ac.uk/~ucakche/), David Bradley [ctb] (https://github.com/DBradley27), Houyun Huang [ctb] (https://github.com/houyunhuang)
Initial release
2021-05-08

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.