scale_dendrogram | R Documentation |
When discrete data has some inherent hierarchy to the relationship between
discrete categories, you can display a dendrogram instead of a tick axis.
These functions have been deprecated in favour of
legendry::scale_{x/y}_dendro()
.
scale_x_dendrogram(
...,
hclust = waiver(),
expand = waiver(),
guide = waiver(),
position = "bottom"
)
scale_y_dendrogram(
...,
hclust = waiver(),
expand = waiver(),
guide = waiver(),
position = "left"
)
The dendrogram type of scale does two things, first it reorders the
values along the relevant direction such that they follow the order
captured in the hclust
argument. Secondly, it draws the dendrogram
at the axis. The dendrogram visuals inherit from the ticks theme elements,
so defining a linetype for the tick marks sets the linetype for the
dendrogram.
A ScaleDendrogram ggproto object.
# Hierarchically cluster USArrests
yclus <- hclust(dist(USArrests), "ave")
xclus <- hclust(dist(t(USArrests)), "ave")
# Melting USArrests
df <- data.frame(
State = rownames(USArrests)[row(USArrests)],
variable = colnames(USArrests)[col(USArrests)],
value = unname(do.call(c, USArrests))
)
# Supply the clustering to the scales
ggplot(df, aes(variable, State, fill = value)) +
geom_raster() +
scale_y_dendrogram(hclust = yclus) +
scale_x_dendrogram(hclust = xclus)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.