Usage
# S3 method for class 'dendrogram'
fortify_data_frame(
data,
...,
priority = "right",
center = FALSE,
type = "rectangle",
leaf_pos = NULL,
leaf_braches = NULL,
reorder_branches = TRUE,
branch_gap = NULL,
root = NULL,
double = TRUE,
data_arg = NULL,
call = NULL
)
# S3 method for class 'hclust'
fortify_data_frame(data, ...)Arguments
- data
A
hclustor adendrogramobject.- ...
Additional arguments passed to
dendrogrammethod.- priority
A string of "left" or "right". if we draw from
righttoleft, the left will override the right, so we take the"left"as the priority. If we draw fromlefttoright, the right will override the left, so we take the"right"as priority. This is used byalign_dendro()to provide support of facet operation in ggplot2.- center
A boolean value. if
TRUE, nodes are plotted centered with respect to all leaves/tips in the branch. Otherwise (default), plot them in the middle of the direct child nodes.- type
A string indicates the plot type,
"rectangle"or"triangle".- leaf_pos
The x-coordinates of the leaf node. Must be the same length of the number of observations in
tree.- leaf_braches
Branches of the leaf node. Must be the same length of the number of observations in
tree. Usually come from cutree.- reorder_branches
A single boolean value, indicates whether reorder the provided
leaf_brachesbased on the actual index.- branch_gap
A single numeric value indicates the gap between different branches.
- root
A length one string or numeric indicates the root branch.
- double
A single logical value indicating whether horizontal lines should be doubled when segments span multiple branches. If
TRUE, the horizontal lines will be repeated for each branch that the segment spans. IfFALSE, only one horizontal line will be drawn. This is used byalign_dendro()to provide support of facet operation in ggplot2.- data_arg
The argument name for
data. Developers can use it to improve messages. Not used by the user.- call
The execution environment where
dataand other arguments for the method are collected. Developers can use it to improve messages. Not used by the user.
Value
A data frame with the node coordinates:
.panel: Similar withpanelcolumn, but always give the correct branch for usage of the ggplot facet..index: the original index in the tree for the the nodelabel: node label textxandy: x-axis and y-axis coordinates for the nodebranch: which branch the node is. You can use this column to color different groups.panel: which panel the node is, if we split the plot into panel using facet_grid, this column will show which panel the node is from. Note: some nodes may fall outside panel (between two panels), so there are possibleNAvalues in this column.leaf: A logical value indicates whether the node is a leaf.
ggalign attributes
edge: A data frame for edge coordinates:
.panel: Similar withpanelcolumn, but always give the correct branch for usage of the ggplot facet.xandy: x-axis and y-axis coordinates for the start node of the edge.xendandyend: the x-axis and y-axis coordinates of the terminal node for edge.branch: which branch the edge is. You can use this column to color different groups.panel1andpanel2: The panel1 and panel2 columns have the same functionality aspanel, but they are specifically for theedgedata and correspond to both nodes of each edge.
Examples
fortify_data_frame(hclust(dist(USArrests), "ave"))
#> .index label x y branch leaf panel .panel
#> 1 9 Florida 1.000000 0.000000 root TRUE <NA> <NA>
#> 2 33 North Carolina 2.000000 0.000000 root TRUE <NA> <NA>
#> 3 NA <NA> 1.500000 38.527912 root FALSE <NA> <NA>
#> 4 5 California 3.000000 0.000000 root TRUE <NA> <NA>
#> 5 20 Maryland 4.000000 0.000000 root TRUE <NA> <NA>
#> 6 3 Arizona 5.000000 0.000000 root TRUE <NA> <NA>
#> 7 31 New Mexico 6.000000 0.000000 root TRUE <NA> <NA>
#> 8 NA <NA> 5.500000 13.896043 root FALSE <NA> <NA>
#> 9 NA <NA> 4.750000 15.453120 root FALSE <NA> <NA>
#> 10 NA <NA> 3.875000 28.012211 root FALSE <NA> <NA>
#> 11 8 Delaware 7.000000 0.000000 root TRUE <NA> <NA>
#> 12 1 Alabama 8.000000 0.000000 root TRUE <NA> <NA>
#> 13 18 Louisiana 9.000000 0.000000 root TRUE <NA> <NA>
#> 14 NA <NA> 8.500000 15.454449 root FALSE <NA> <NA>
#> 15 NA <NA> 7.750000 16.891499 root FALSE <NA> <NA>
#> 16 13 Illinois 10.000000 0.000000 root TRUE <NA> <NA>
#> 17 32 New York 11.000000 0.000000 root TRUE <NA> <NA>
#> 18 NA <NA> 10.500000 6.236986 root FALSE <NA> <NA>
#> 19 22 Michigan 12.000000 0.000000 root TRUE <NA> <NA>
#> 20 28 Nevada 13.000000 0.000000 root TRUE <NA> <NA>
#> 21 NA <NA> 12.500000 13.297368 root FALSE <NA> <NA>
#> 22 NA <NA> 11.500000 18.417331 root FALSE <NA> <NA>
#> 23 NA <NA> 9.625000 26.363428 root FALSE <NA> <NA>
#> 24 2 Alaska 14.000000 0.000000 root TRUE <NA> <NA>
#> 25 24 Mississippi 15.000000 0.000000 root TRUE <NA> <NA>
#> 26 40 South Carolina 16.000000 0.000000 root TRUE <NA> <NA>
#> 27 NA <NA> 15.500000 21.167192 root FALSE <NA> <NA>
#> 28 NA <NA> 14.750000 28.095803 root FALSE <NA> <NA>
#> 29 NA <NA> 12.187500 39.394633 root FALSE <NA> <NA>
#> 30 NA <NA> 8.031250 44.283922 root FALSE <NA> <NA>
#> 31 NA <NA> 4.765625 77.605024 root FALSE <NA> <NA>
#> 32 47 Washington 17.000000 0.000000 root TRUE <NA> <NA>
#> 33 37 Oregon 18.000000 0.000000 root TRUE <NA> <NA>
#> 34 50 Wyoming 19.000000 0.000000 root TRUE <NA> <NA>
#> 35 36 Oklahoma 20.000000 0.000000 root TRUE <NA> <NA>
#> 36 46 Virginia 21.000000 0.000000 root TRUE <NA> <NA>
#> 37 NA <NA> 20.500000 7.355270 root FALSE <NA> <NA>
#> 38 NA <NA> 19.750000 10.736739 root FALSE <NA> <NA>
#> 39 NA <NA> 18.875000 12.878100 root FALSE <NA> <NA>
#> 40 NA <NA> 17.937500 16.425489 root FALSE <NA> <NA>
#> 41 39 Rhode Island 22.000000 0.000000 root TRUE <NA> <NA>
#> 42 21 Massachusetts 23.000000 0.000000 root TRUE <NA> <NA>
#> 43 30 New Jersey 24.000000 0.000000 root TRUE <NA> <NA>
#> 44 NA <NA> 23.500000 11.456439 root FALSE <NA> <NA>
#> 45 NA <NA> 22.750000 22.595978 root FALSE <NA> <NA>
#> 46 NA <NA> 20.343750 26.713777 root FALSE <NA> <NA>
#> 47 25 Missouri 25.000000 0.000000 root TRUE <NA> <NA>
#> 48 4 Arkansas 26.000000 0.000000 root TRUE <NA> <NA>
#> 49 42 Tennessee 27.000000 0.000000 root TRUE <NA> <NA>
#> 50 NA <NA> 26.500000 12.614278 root FALSE <NA> <NA>
#> 51 NA <NA> 25.750000 20.198479 root FALSE <NA> <NA>
#> 52 10 Georgia 28.000000 0.000000 root TRUE <NA> <NA>
#> 53 6 Colorado 29.000000 0.000000 root TRUE <NA> <NA>
#> 54 43 Texas 30.000000 0.000000 root TRUE <NA> <NA>
#> 55 NA <NA> 29.500000 14.501034 root FALSE <NA> <NA>
#> 56 NA <NA> 28.750000 23.972143 root FALSE <NA> <NA>
#> 57 NA <NA> 27.250000 29.054195 root FALSE <NA> <NA>
#> 58 NA <NA> 23.796875 44.837933 root FALSE <NA> <NA>
#> 59 12 Idaho 31.000000 0.000000 root TRUE <NA> <NA>
#> 60 27 Nebraska 32.000000 0.000000 root TRUE <NA> <NA>
#> 61 17 Kentucky 33.000000 0.000000 root TRUE <NA> <NA>
#> 62 26 Montana 34.000000 0.000000 root TRUE <NA> <NA>
#> 63 NA <NA> 33.500000 3.834058 root FALSE <NA> <NA>
#> 64 NA <NA> 32.750000 12.438692 root FALSE <NA> <NA>
#> 65 NA <NA> 31.875000 15.026107 root FALSE <NA> <NA>
#> 66 35 Ohio 35.000000 0.000000 root TRUE <NA> <NA>
#> 67 44 Utah 36.000000 0.000000 root TRUE <NA> <NA>
#> 68 NA <NA> 35.500000 6.637771 root FALSE <NA> <NA>
#> 69 14 Indiana 37.000000 0.000000 root TRUE <NA> <NA>
#> 70 16 Kansas 38.000000 0.000000 root TRUE <NA> <NA>
#> 71 NA <NA> 37.500000 3.929377 root FALSE <NA> <NA>
#> 72 7 Connecticut 39.000000 0.000000 root TRUE <NA> <NA>
#> 73 38 Pennsylvania 40.000000 0.000000 root TRUE <NA> <NA>
#> 74 NA <NA> 39.500000 8.027453 root FALSE <NA> <NA>
#> 75 NA <NA> 38.500000 13.352260 root FALSE <NA> <NA>
#> 76 NA <NA> 37.000000 15.122897 root FALSE <NA> <NA>
#> 77 NA <NA> 34.437500 20.598507 root FALSE <NA> <NA>
#> 78 11 Hawaii 41.000000 0.000000 root TRUE <NA> <NA>
#> 79 48 West Virginia 42.000000 0.000000 root TRUE <NA> <NA>
#> 80 19 Maine 43.000000 0.000000 root TRUE <NA> <NA>
#> 81 41 South Dakota 44.000000 0.000000 root TRUE <NA> <NA>
#> 82 NA <NA> 43.500000 8.537564 root FALSE <NA> <NA>
#> 83 NA <NA> 42.750000 10.771175 root FALSE <NA> <NA>
#> 84 34 North Dakota 45.000000 0.000000 root TRUE <NA> <NA>
#> 85 45 Vermont 46.000000 0.000000 root TRUE <NA> <NA>
#> 86 NA <NA> 45.500000 13.044922 root FALSE <NA> <NA>
#> 87 23 Minnesota 47.000000 0.000000 root TRUE <NA> <NA>
#> 88 49 Wisconsin 48.000000 0.000000 root TRUE <NA> <NA>
#> 89 15 Iowa 49.000000 0.000000 root TRUE <NA> <NA>
#> 90 29 New Hampshire 50.000000 0.000000 root TRUE <NA> <NA>
#> 91 NA <NA> 49.500000 2.291288 root FALSE <NA> <NA>
#> 92 NA <NA> 48.750000 10.184218 root FALSE <NA> <NA>
#> 93 NA <NA> 47.875000 18.993398 root FALSE <NA> <NA>
#> 94 NA <NA> 46.687500 27.779904 root FALSE <NA> <NA>
#> 95 NA <NA> 44.718750 33.117815 root FALSE <NA> <NA>
#> 96 NA <NA> 42.859375 41.094765 root FALSE <NA> <NA>
#> 97 NA <NA> 38.648438 54.746831 root FALSE <NA> <NA>
#> 98 NA <NA> 31.222656 89.232093 root FALSE <NA> <NA>
