scale_x_dendro | R Documentation |
These are speciality scales for use with hierarchically clustered data. The scale automatically orders the limits according to the clustering result and comes with a dendrogram axis.
scale_x_dendro(
clust,
...,
expand = waiver(),
guide = "axis_dendro",
position = "bottom"
)
scale_y_dendro(
clust,
...,
expand = waiver(),
guide = "axis_dendro",
position = "left"
)
clust |
A data structure that can be coerced to an
|
... |
Arguments passed on to
|
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 scale limits are determined by the order and labels in the clust
argument. While limits
is not an argument in these scales, the breaks
argument can still be used to selectively omit some breaks and the labels
can be used for formatting purposes.
A <ScaleDiscretePosition>
object that can be added to a plot.
guide_axis_dendro()
# Hierarchically cluster data, separately for rows and columns
car_clust <- hclust(dist(scale(mtcars)), "ave")
var_clust <- hclust(dist(scale(t(mtcars))), "ave")
long_mtcars <- data.frame(
car = rownames(mtcars)[row(mtcars)],
var = colnames(mtcars)[col(mtcars)],
value = as.vector(scale(mtcars))
)
# A standard heatmap adorned with dendrograms
p <- ggplot(long_mtcars, aes(var, car, fill = value)) +
geom_tile() +
scale_x_dendro(var_clust) +
scale_y_dendro(car_clust)
p
# Styling the dendrograms
p +
guides(
y = guide_axis_dendro(key_dendro(type = "triangle")),
x = guide_axis_dendro(space = rel(5))
) +
theme(
axis.text.y.left = element_text(margin = margin(r = 3, l = 3)),
axis.ticks.y = element_line("red"),
axis.ticks.x = element_line(linetype = "dotted")
)
# In polar coordinates, plus some formatting
p +
coord_radial(
theta = "y", inner.radius = 0.5,
start = 0.25 * pi, end = 1.75 * pi
) +
guides(
theta = primitive_labels(angle = 90),
theta.sec = primitive_segments("dendro", vanish = TRUE),
r = guide_axis_dendro(angle = 0)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.