clust <- hclust(dist(USArrests), "ave")
# Melting USArrests
df <- data.frame(
State = rownames(USArrests)[row(USArrests)],
variable = colnames(USArrests)[col(USArrests)],
value = unname(do.call(c, USArrests))
)
# The guide function can be used to customise the axis
g <- ggplot(df, aes(variable, State, fill = value)) +
geom_raster() +
scale_y_dendrogram(hclust = clust,
guide = guide_dendro(n.dodge = 2))
# The looks of the dendrogram are controlled through ticks
g + theme(axis.ticks = element_line(colour = "red"))
# The size of the dendrogram is controlled through tick size * 10
g + theme(axis.ticks.length = unit(5, "pt"))
Run the code above in your browser using DataLab