我想通过grid.arrange
函数合并来自聚类结果的两个树形图。我使用的代码是
d.a <- dist(df.a, method = "euclidean")
# Hierarchical clustering
res.hc.a <- hclust(d.a, method = "ward.D2" )
d.b <- dist(df.b, method = "euclidean")
# Hierarchical clustering
res.hc.b <- hclust(d.b, method = "ward.D2" )
p1=plot(res.hc.a, cex = 0.75,main="a")
rect.hclust(res.hc.a, k = 6, border = 2:7)
p2=plot(res.hc.b, cex = 0.75,main="b")
rect.hclust(res.hc.b, k = 7, border = 2:8)
grid.arrange(p1, p2, ncol = 2, top = "Dendrograms")
但是我遇到了像这样的错误
Error in gList(list(wrapvp = list(x = 0.5, y = 0.5, width = 1, height = 1, :
only 'grobs' allowed in "gList"
问题是grid.arrange
函数不考虑每个绘图代码的第二行。我不知道如何解决这个问题。我的第二个问题是我想要显示每个树形图而不是水平线。有什么想法吗?