r - 将ggballoonplot与R中的树状图结合起来
问题描述
我有一个使用 pacakge 的简单气球图ggpballoonplot
:
ggballoonplot(X, x = "cluster", y = "marker", size = "Relative.Expression",
fill = "Median.Intensity",
ggtheme = theme_classic())
我想知道是否可以添加树状图并根据它组织气球图?我知道你可以做类似的事情,corrplot
如:Dendrogram with Corrplot (R)但是很难将它应用到ggballoonplot
函数中?
解决方案
经过几次尝试后,我发现将两者结合起来的最佳方法是:
### 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.
欢迎替代解决方案。
推荐阅读
- php - 更新实体对象时无法在 foreach 循环外调用 entityManager->flush()
- canjs - 如何从动态生成的表单元素中获取值
- kotlin - 发行人赎回另一方持有的可替代代币
- reactjs - 未捕获的类型错误:无法读取未定义的属性“setState”
- python-3.x - pyqt5 的 pyinstaller 错误。无法运行分发文件。加载两组 Qt 二进制文件?
- php - 如何测试生成的 php 文件?
- ssis - 是否可以从 SSIS 中的数据流窗格发送邮件
- javascript - 如何修复 cy.route() 数据类型响应问题?
- javascript - 如何循环通过 Socket.onmessage() - javascript
- c# - 如何在三元运算符中使用 void 函数(不同的参数)调用或在 1 行中编写 if-else