Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm referring to something like this:

alt text

suggested dataset for showing a solutions:


locked by whuber Jul 10 '15 at 14:08

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

What is the advantage of a polar representation (aside from saving space)? It looks to me like it is trickier to look at. – nico Oct 29 '10 at 9:56
@nico It is more cool (-; – mbq Oct 29 '10 at 10:08
It is also useful when you don't have one stem... – Tal Galili Oct 29 '10 at 10:29
@mbq: you missed a "good" pun there... you could have said "it's more fan" :) – nico Oct 30 '10 at 8:22

In phylogenetics, this is a fan phylogram, so you can convert this to phylo and use ape:


alt text

(+1) I looked for this one, but cannot found it in the ape package! – chl Oct 29 '10 at 9:56
Bingo. That's what I was looking for. I wonder if there is something similar in ggplot2... – Tal Galili Oct 29 '10 at 10:33
@Tal No official support for tree structures in ggplot2. Look at this Google group thread, (but it's definitively not circular). – chl Oct 30 '10 at 12:52
Hello chl, thank you for the link. I'll respond there with reference to this code as well... – Tal Galili Oct 30 '10 at 23:16

Did you see this post?

Take the example, add coord_polar() and reverse the axes and you get pretty close:

x <- as.phylo(hclust(dist(mtcars)))

p <- ggplot(data=x)
p <- p + geom_segment(aes(y=x,x=y,yend=xend,xend=yend), colour="blue",alpha=1) 
p <- p + geom_text(data=label.phylo(x), aes(x=y, y=x, label=label),family=3, size=3) + xlim(0, xlim) + coord_polar()

theme <- theme_update(  axis.text.x = theme_blank(),
                        axis.ticks = theme_blank(),
                        axis.title.x = theme_blank(),
                        axis.title.y = theme_blank(),
                        legend.position = "none"
p <- p + theme_set(theme)
Dear Charlotte, this is very helpful, thank you! – Tal Galili Nov 5 '10 at 4:36
p <- ggplot(data=x) I get this error: ggplot2 doesn't know how to deal with data of class phylo. What am I missing? – GaBorgulya Apr 14 '11 at 23:42
up vote 1 down vote accepted

Four years later, I am now able to answer this question. It can be done by combining two new packages: circlize and dendextend.

The plot can be made using the circlize_dendrogram function (allowing for a much more refined control over the "fan" layout of the plot.phylo function).

# install.packages("dendextend")
# install.packages("circlize")

# create a dendrogram
hc <- hclust(dist(datasets::mtcars))
dend <- as.dendrogram(hc)

# modify the dendrogram to have some colors in the branches and labels
dend <- dend %>% 
   color_branches(k=4) %>% 

# plot the radial plot
par(mar = rep(0,4))
# circlize_dendrogram(dend, dend_track_height = 0.8) 
circlize_dendrogram(dend, labels_track_height = NA, dend_track_height = .4) 

And the result is:

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.