如何使用R/igraph设置边缘颜色和顶点间距 [英] How to set edge colors and vertex spacing with R / igraph

查看:467
本文介绍了如何使用R/igraph设置边缘颜色和顶点间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是R的新手,他试图弄清楚如何为我拥有数据的系统制作社交网络图.

I am new to R and trying to figure out how to make a social network map of a system that I have data for.

我已经从FAQ和教程中找出了我想做的大部分事情,但是我在两件事上陷入了困境.

I have managed to figure out most of what I want to do from the FAQ and tutorials, but I am stuck on two things.

  1. 如何使画布变大/图形更隔开?现在太压扁了.

  1. How do I make the canvas larger / the graph more spaced out? Right now it's way too squashed.

目前,边缘厚度是根据重量设置的.权重代表不同的状态(8 =活动,3 =请求,2 =隐藏,1 =阻止),我想设置边缘的样式而不是更改其厚度.在理想情况下,绿色表示活动,绿色虚线表示请求,黑色表示隐藏,红色表示被阻止.一个潜在的问题是权重在两个方向上可能都不相同(即u53可能隐藏或阻止了u114,但u114却没有对u53进行任何操作).我不确定该怎么做:)

At the moment the edge thickness is set based on the weight. The weights represent different statuses (8 = Active, 3 = Requested, 2 = Hidden, 1 = Blocked) and I would like to style the edges rather than change their thickness. In an ideal world, green for Active, green dashed for Requested, black for hidden and red for blocked. One potential problem is that the weights may not be the same in both directions (i.e. u53 could be hiding or blocking u114, but u114 isn't doing either to u53). I am not sure what to do about that :)

我已经在 http:/上放置了一些示例数据和代码. /www.r-fiddle.org/#/fiddle?id=7a2Aiql2&version=3

中用颜色(感谢@Chris)更新了小提琴. http://www.r-fiddle.org/#/fiddle?id=7a2Aiql2&version=5 -仍未想出如何制作更大的地块,因此有足够的空间!

Updated fiddle with colors (thanks @Chris) at http://www.r-fiddle.org/#/fiddle?id=7a2Aiql2&version=5 - still haven't worked out how to make a bigger plot so there's room for it all!

谢谢!

推荐答案

  1. 您可以将ylimxlim参数的值更改为plot.igraph(也许还有asp参数).如果这些都不起作用,则可能必须赋予顶点xy属性以将它们隔开.
  2. 要根据重量为边缘着色,您可以做

  1. You can change the values for the ylim and xlim arguments to plot.igraph (and perhaps also the asp argument). If none of those works, then you may have to give the vertices x and y attributes to space them out.
  2. To color edges based on weight, you would do e.g.

E(g)$color[E(g)$weight == 8] <- 'green'
E(g)$lty[E(g)$weight == 8] <- 1
E(g)$color[E(g)$weight == 3] <- 'green'
E(g)$lty[E(g)$weight == 3] <- 2

以此类推.您剩下的问题更多取决于您的个人喜好.

And so on. The rest of your question is more up to your personal preference.

这篇关于如何使用R/igraph设置边缘颜色和顶点间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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