【问题标题】:Plotting group distances in R在 R 中绘制组距离
【发布时间】:2014-08-05 00:19:30
【问题描述】:

我有一个组距离矩阵G 如下

G <- data.frame( Gp1=c(6.525,15.915,16.605,10.665,19.345), Gp2=c(15.915,8.605,31.455,25.485,48.355), Gp3=c(16.605,31.455,7.955,11.195,33.685), Gp4=c(10.665,25.485,11.195,0,21.985), Gp5=c(19.345,48.355,33.685,21.985,0))
rownames(G) <- colnames(G)

G
       Gp1    Gp2    Gp3    Gp4    Gp5
Gp1  6.525 15.915 16.605 10.665 19.345
Gp2 15.915  8.605 31.455 25.485 48.355
Gp3 16.605 31.455  7.955 11.195 33.685
Gp4 10.665 25.485 11.195  0.000 21.985
Gp5 19.345 48.355 33.685 21.985  0.000

对角线是组内距离。

我想在下面的情节中描述上述内容。它不需要缩放到距离值。如何在R 中生成它?

【问题讨论】:

    标签: r plot ggplot2 visualization


    【解决方案1】:

    使用 qgraph 得到解决方案

    G <- data.frame( Gp1=c(6.525,15.915,16.605,10.665,19.345), Gp2=c(15.915,8.605,31.455,25.485,48.355), Gp3=c(16.605,31.455,7.955,11.195,33.685), Gp4=c(10.665,25.485,11.195,0,21.985), Gp5=c(19.345,48.355,33.685,21.985,0))
    rownames(G) <- colnames(G)
    
    rownames(G) <- colnames(G) <- as.character(as.roman(seq(length.out=nrow(G))))
    qgraph(G, layout = "circle", usePCH = TRUE,
            normalise = TRUE,
            vsize = 7, color = "gray90", node.width = 1,
            border.width = 1.7, diag = FALSE,
            label.prop = 0.6,
            labels = paste(rownames(G),diag(as.matrix(G)),sep="\n"),
            esize = 1, edge.labels = TRUE, edge.color = "black", fade=FALSE,
            lty = "dotted", edge.label.cex = 0.7, edge.label.bg = "white",
            directed = TRUE, arrows = FALSE, bidirectional = TRUE,
            asize = 1.5, weighted = FALSE)
    

    【讨论】:

      【解决方案2】:

      这非常接近:

      [注:合并@Jealie 的建议并进行了一些其他更改。现在更接近您的预期结果。]

      rownames(G) <- colnames(G) <- c("I","II","III","IV","V")
      G[lower.tri(G)] <- 0
      library(igraph)
      g <- graph.adjacency(as.matrix(G),weight=T, mode="undirected")
      g <- simplify(g,remove.loops=TRUE)
      plot(g,edge.label=E(g)$weight, 
           vertex.label=paste(V(g)$name,diag(as.matrix(G)),sep="\n"),
           layout=layout.circle,
           vertex.size=30)
      

      我不知道有一种方法可以使边缘标签与边缘平行,但这并不意味着它不能'完成......

      【讨论】:

      • 您可以在对 graph.adjacency 的调用中添加 mode="undirected" 以删除箭头
      • @Jealie - 好收获。我什至没有注意到缺少箭头...我已经采纳了您的建议。
      • @jlhoward 这正是我想要的。现在我试图通过摆弄igraph 来让 edge.labels 更具可读性。
      猜你喜欢
      • 2014-05-23
      • 2011-10-12
      • 2018-02-25
      • 2020-10-17
      • 1970-01-01
      • 2018-09-28
      • 2017-08-26
      • 1970-01-01
      • 2021-11-02
      相关资源
      最近更新 更多