How to set edge colors and vertex spacing with R / igraph

喜欢而已 提交于 2020-01-13 11:53:12

问题


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.

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. How do I make the canvas larger / the graph more spaced out? Right now it's way too squashed.

  2. 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 :)

I have put some sample data and code at http://www.r-fiddle.org/#/fiddle?id=7a2Aiql2&version=3

EDIT: 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!

Thanks!


回答1:


  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.



来源:https://stackoverflow.com/questions/31418599/how-to-set-edge-colors-and-vertex-spacing-with-r-igraph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!