plot_horiz.dendrogram: Plotting a left-tip-adjusted horizontal dendrogram

Description Usage Arguments Value Source See Also Examples

View source: R/tanglegram.R

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

1
2
3
4
5
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

plot.dendrogram, tanglegram

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
## 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)

Example output

---------------------
Welcome to dendextend version 1.5.2
Type citation('dendextend') for how to cite the package.

Type browseVignettes(package = 'dendextend') for the package vignette.
The github page is: https://github.com/talgalili/dendextend/

Suggestions and bug-reports can be submitted at: https://github.com/talgalili/dendextend/issues
Or contact: <tal.galili@gmail.com>

	To suppress this message use:  suppressPackageStartupMessages(library(dendextend))
---------------------


Attaching package: 'dendextend'

The following object is masked from 'package:stats':

    cutree

Warning messages:
1: In plot.window(...) : "text_offset" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "text_offset" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  "text_offset" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  "text_offset" is not a graphical parameter
5: In title(...) : "text_offset" is not a graphical parameter
Warning messages:
1: In plot.window(...) : "text_offset" is not a graphical parameter
2: In plot.xy(xy, type, ...) : "text_offset" is not a graphical parameter
3: In axis(side = side, at = at, labels = labels, ...) :
  "text_offset" is not a graphical parameter
4: In axis(side = side, at = at, labels = labels, ...) :
  "text_offset" is not a graphical parameter
5: In title(...) : "text_offset" is not a graphical parameter

dendextend documentation built on Oct. 19, 2018, 9:03 a.m.