I have a simple balloonplot using the ggpballoonplot
pacakge:
ggballoonplot(X, x = "cluster", y = "marker", size = "Relative.Expression",
fill = "Median.Intensity",
ggtheme = theme_classic())
I wanted to know if it was possible to add a dendrogram and organise the balloon plot based on that? I know you can do a similar thing with corrplot
as seen in : Dendrogram with Corrplot (R) but was struggling to apply it to theggballoonplot
function?
After several attempts later I have found that the best way to combine the two is by:
### Build the dendrogram
dend <- as.dendrogram(hclust(d = dist(x = X)))
dendro.plot <- ggdendrogram(dend,rotate = TRUE)
### Use dendrogram order to order column
order <- order.dendrogram(dend) # dendrogram order
X$marker <- factor(x = X$marker,levels = X$marker[order],ordered = TRUE)
### then use grid to combine the two
grid.newpage()
print(balloon.plot, vp = viewport(x = 0.4, y = 0.45, width = 0.8, height = 0.76))
print(dend, vp = viewport(x = 0.885, y = 0.435, width = 0.2, height = 0.84))
## requires trial and error to get it into the right position.
## Also ensure that xticks and yticks and labels are set to blank.
Alternative solutions welcome.