问题
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.
How do I make the canvas larger / the graph more spaced out? Right now it's way too squashed.
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:
- You can change the values for the
ylim
andxlim
arguments toplot.igraph
(and perhaps also theasp
argument). If none of those works, then you may have to give the verticesx
andy
attributes to space them out. 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