[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] extracting x y values from an igraph object to plot in ggpl

From: address@hidden
Subject: Re: [igraph] extracting x y values from an igraph object to plot in ggplot
Date: Mon, 11 Jun 2012 19:11:43 +0200


You can also use my code for plotting network with ggplot2


graph = graph.formula(A-B-C-D-E)
V(graph)$group = rainbow(vcount(graph))
E(graph)$weight = round(rnorm(nrow(get.edgelist(graph))),digits=2)
# Once you have igraph graph object with weight and group attributes
ggnetwork(graph, layout.circle(graph))

On 11 June 2012 17:06, Roey Angel <address@hidden> wrote:
Wow thanks for the rapid and very helpful reply, Gabor!
That's all I wanted to know.


On 06/11/2012 04:43 PM, Gábor Csárdi wrote:

On Mon, Jun 11, 2012 at 10:36 AM, Roey Angel<address@hidden>  wrote:
I'd like to extract the x y values from an igraph object in order to plot it
in ggplot (which accepts only data frames).
there are not x y values in igraph objects, at least not by default.

Scott Chamberlain has published an attempt to plot igraph networks in ggplot
(http://schamberlain.github.com/2011/03/basic-ggplot2-network-graphs/) but
he's just generating random values for the position of the vertices (through
the vplace variable).
This works fine for small networks but makes a clutter in large networks
and, most importantly, doesn't allow drawing different layouts.
You can generate layout coordinates by using one of the several layout
functions, e.g.
xy<- layout.fruchterman.reingold(mygraph)

The reason I'm insisting on ggplot (apart from the fact that this is what I
know best in R graphics) is because I'd like to have the vertices sized
according to a vector of numeric values and their colours according to a
character vector and that's done very easly in ggplot.
This is actually quite easy without ggplot as well:

G<- graph.ring(10)
plot(G, vertex.size=1:10*2, vertex.color=rainbow(10), layout=layout.circle)


I'm a beginner and trying to figure out my way in the world of networks and
igraph so there might be something very basic I'm missing out here.

Thanks a lot in advance,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]