Debian Codegraph @

man/get_nodes_xy.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/get_nodes_xy.R
3 \name{get_nodes_xy}
4 \alias{get_nodes_xy}
5 \title{Get the x-y coordinates of a dendrogram's nodes}
6 \source{
7 This is a striped down version of the
8 function \code{\link{plot.dendrogram}}.
9 It performs (almost) the same task, only it does not do any plotting
10 but it does save the x-y coordiantes of the nodes.
11 }
12 \usage{
13 get_nodes_xy(
14 dend,
15 type = c("rectangle", "triangle"),
16 center = FALSE,
17 horiz = FALSE,
18 ...
19 )
20 }
21 \arguments{
22 \item{dend}{a dendrogram object}
23
24 \item{type}{type of plot.}
25
26 \item{center}{logical; if TRUE, nodes are plotted centered with respect to the
27 leaves in the branch. Otherwise (default),
28 plot them in the middle of all direct child nodes.}
29
30 \item{horiz}{logical indicating if the dendrogram should be drawn horizontally or not.}
31
32 \item{...}{not used}
33 }
34 \value{
35 A 2-dimensional matrix, with rows as the number of nodes,
36 and the first column is the x location, while the second is the
37 y location.
38 }
39 \description{
40 Get the x-y coordinates of a dendrogram's nodes. Can be used to add text or images on the tree.
41 }
42 \examples{
43 \dontrun{
44
45 # If we would like to see the numbers from plot:
46 # ?getOption("verbose")
47 # options(verbose=TRUE)
48 # options(verbose=FALSE)
49
50 # -----
51 # Draw a depth first search illustration
52 # -----
53
54 dend <- 1:5 \%>\%
55 dist() \%>\%
56 hclust() \%>\%
57 as.dendrogram()
58 get_nodes_xy(dend)
59
60 # polygon(get_nodes_xy(dend), col = 2)
61 plot(dend,
62 leaflab = "none",
63 main = "Depth-first search in a dendrogram"
64 )
65 xy <- get_nodes_xy(dend)
66 for (i in 1:(nrow(xy) - 1)) {
67 arrows(xy[i, 1], xy[i, 2],
68 angle = 17,
69 length = .5,
70 xy[i + 1, 1], xy[i + 1, 2],
71 lty = 1, col = 3, lwd = 1.5
72 )
73 }
74 points(xy, pch = 19, cex = 4)
75 text(xy, labels = 1:nnodes(dend), cex = 1.2, col = "white", adj = c(0.4, 0.4))
76 }
77 }
78 \seealso{
79 \link{get_nodes_attr}, \link{nnodes},
80 \link{nleaves}
81 }