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.
scale_x_dendrogram(
...,
hclust = waiver(),
expand = waiver(),
guide = waiver(),
position = "bottom"
)
scale_y_dendrogram(
...,
hclust = waiver(),
expand = waiver(),
guide = waiver(),
position = "left"
)
... |
Arguments passed on to
|
hclust |
An object of the type produced by the
|
expand |
For position scales, a vector of range expansion constants used to add some
padding around the data to ensure that they are placed some distance
away from the axes. Use the convenience function |
guide |
A function used to create a guide or its name. See
|
position |
For position scales, The position of the axis.
|
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.