在R中绘制组距离 [英] Plotting group distances in R

查看:116
本文介绍了在R中绘制组距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组距离矩阵G,如下所示:

I have a matrix of group distances G as follows

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

对角线是组内的距离.

The diagonal is the within group distances.

我想在下面的图中描述上述内容.不一定要缩放到距离值.如何在R中生产它?

I would like to depict the above in a plot as follows. It need not be to scale to the distance values. How to produce it in R?

推荐答案

这非常接近:

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

[Note: Incorporated @Jealie's suggestion and made a few other changes. It's a bit closer to your intended result now.]

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)

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

I'm not aware of a way to make the edge labels parallel to the edges, but that doesn't mean it cant' be done...

这篇关于在R中绘制组距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆