talgalili / dendextend

Extending R's Dendrogram Functionality
153 stars 29 forks source link

Is it possible to "mirror" a dendrogram? #29

Closed EOneita closed 8 years ago

EOneita commented 8 years ago

I have attached the image of the dendrogram I have created. Is there a code in ddextend that can be used to mirror this image? So, I would have the questions on the left, and the tree extending to the left, as an inverse of what is seen here.

I've been looking through the ddextend manual for code to this effect, but have struggled to find any.

Thank you in advance for your help, Elizabeth

screen shot 2016-10-12 at 10 56 27
talgalili commented 8 years ago

Good question. The function you are looking for is dendextend::plot_horiz.dendrogram. This function is indeed not documented in the vignettes, although it is used by tanglegram. Here is an example for how to use it, I hope this helps:

hc <- hclust(dist(USArrests), "ave")
d <- as.dendrogram(hc)
plot(d, horiz  = TRUE)

library(dendextend)
d <- d %>% color_branches(k=3) %>% color_labels

par(mar = c(3,7,1,1))
plot_horiz.dendrogram(d, side = TRUE)

Output

image

With regards, Tal

EOneita commented 8 years ago

Great, thank you so much! Worked like a charm.