【问题标题】:Combine ggballoonplot with dendrogram in R将ggballoonplot与R中的树状图结合起来
【发布时间】:2020-10-19 13:37:48
【问题描述】:

我有一个使用ggpballoonplot pacakge 的简单气球图:

ggballoonplot(X, x = "cluster", y = "marker", size = "Relative.Expression",
              fill = "Median.Intensity", 
              ggtheme = theme_classic()) 

我想知道是否可以添加树状图并根据它组织气球图?我知道你可以用corrplot 做类似的事情,如:Dendrogram with Corrplot (R),但很难将其应用于ggballoonplot 函数?

【问题讨论】:

    标签: r ggplot2 dendrogram bubble-chart ggdendro


    【解决方案1】:

    经过几次尝试后,我发现将两者结合起来的最佳方法是:

    ### 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.
    

    欢迎使用替代解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多