在 R 中结合 ggballoonplot 和树状图
Combine ggballoonplot with dendrogram in R
我有一个使用 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.
欢迎提供替代解决方案。
我有一个使用 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.
欢迎提供替代解决方案。