geom_dendrogram ¶
geom_dendrogram(
tree: ClusterTree,
*,
type: Literal = "rectangle",
orientation: Literal["x", "y"] = "x",
color: str | None = None,
size: Number | None = None,
linetype: str | int | None = None,
alpha: Number | None = None,
**other_args: Any,
) -> LayerSpec
Draw a clustering tree as line segments (R ggdendro).
Leaf i of the tree's order sits at position i (0, 1, 2, ...: the places
of a discrete axis, so the tree lines up with scale_*_dendro(tree)), the
leaves at height 0 and each node at its merge height.
Parameters:
-
tree(ClusterTree) –The tree, from :func:
hclust. -
type((rectangle, triangle), default:"rectangle") –Elbow links, or straight lines from each node to its children.
-
orientation((x, y), default:"x") –Leaves along x (heights on y, root up), or along y (heights on x).
-
color(optional, default:None) –Segment style, as
geom_segment(). -
size(optional, default:None) –Segment style, as
geom_segment(). -
linetype(optional, default:None) –Segment style, as
geom_segment(). -
alpha(optional, default:None) –Segment style, as
geom_segment(). -
**other_args(Any) –Other
geom_segment()options.
Returns:
-
LayerSpec–A segment layer with its own data (it does not inherit the plot mapping).
Raises:
-
UnsupportedValueError–If
treeis not an :class:ClusterTree. -
SpecError–If
typeororientationis unknown.
Examples:
>>> from ggrust import *
>>> frame = {"car": ["a", "b", "c", "d"], "mpg": [21.0, 22.8, 18.7, 14.3]}
>>> tree = hclust(frame, labels="car")
>>> plot = ggplot() + geom_dendrogram(tree)