teunbrand / ggnomics

A small project to add ggplot2 extensions
https://teunbrand.github.io/ggnomics/
Other
80 stars 4 forks source link

Dendrogram scales for discrete data #34

Closed teunbrand closed 4 years ago

teunbrand commented 4 years ago

For discrete data, implement a scale_x_dendrogram/scale_y_dendrogram function that take a hclust-class object compatible with the discrete values of the data, reorders the axis according to the dendrogram and draws the tree as part of the axis.

Potential later addition could be to dynamically generate the hclust data given the data, instead of having to rely on the user to supply it.

teunbrand commented 4 years ago

This is now possible in the dev branch:

clust <- hclust(dist(USArrests), "ave")

df <- cbind(State = rownames(USArrests),
            USArrests)
df <- reshape2::melt(df, id.vars = "State")

ggplot(df, aes(variable, State, fill = value)) +
  geom_raster() +
  scale_y_dendrogram(hclust = clust)

image

This relies on the ggplot2 v3.3.0 release candidate for the extendible axes system, so Travis CI will fail untill v3.3.0 is on CRAN.

teunbrand commented 4 years ago

In ggh4x now.