简体   繁体   English

将 ggballoonplot 与 R 中的树状图结合

[英]Combine ggballoonplot with dendrogram in R

I have a simple balloonplot using the ggpballoonplot pacakge:我有一个使用ggpballoonplot的简单气球图:

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?我想知道是否可以添加树状图并基于此组织气球 plot? I know you can do a similar thing with corrplot as seen in: Dendrogram with Corrplot (R) but was struggling to apply it to the ggballoonplot function?我知道您可以使用corrplot做类似的事情,如下所示: Dendrogram with Corrplot (R)但正在努力将其应用于ggballoonplot 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.欢迎替代解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM