igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Plotting a signed and directed graph


From: Tom Backer Johnsen
Subject: Re: [igraph] Plotting a signed and directed graph
Date: Tue, 14 Apr 2009 17:46:14 +0200
User-agent: Thunderbird 2.0.0.21 (Windows/20090302)

Gábor Csárdi wrote:
Yes, read.graph does not support reading 'signed' graphs. The thing is
that the Pajek format is not documented and I have never seen a signed
format so far.

Thank you for your workaround, which I will try after this reply. Sorry about taking some time for that, but I had to pick up my daughter from the airport which took some hours.

As to documentation of the Pajek format, there are at least two examples of valued and directed graphs in the book "Exploratory Social Network Analysis with Pajek" by de Nooy, Mrvar, and Batagelj, Cambridge University Press. You will find the examples on pages 8 (valued) and 93 (valued and signed) in that book. Instead of representing the graph as a matrix as I did, the command is *Arcs, followed by a list of the arcs, consisting of a sender (by number from the first part of the file) the receiver (again by number) and then the value. The values are all positive on the one on page 8, and signed on page 93.

As far as I remember, the second and third authors are the authors of the Pajek program, so that is at least some kind of authority. I will send you the same graph in the *Arcs format, then you will have the same structure in two formats.

Tom


Here is a workaround, we need to read in the file "by hand":

## this ignores the -1 distinction edges but reads the vertex
attributes at least
g <- read.graph("/tmp/signed.net", format="pajek")

## by hand, only the lines after "*Matrix"
lines <- readLines("/tmp/signed.net")
matline <- grep("^.Matrix", lines)
lines2 <- paste(collapse="\n", lines[(matline+1):length(lines)])

A <- matrix(scan(textConnection(lines2)), byrow=TRUE, vcount(g))

g2 <- graph.adjacency(A, weighted=TRUE)
E(g2)$sign <- E(g2)$weight
V(g2)$id <- V(g)$id
g <- g2

Btw. the graph is quite dense, you might want to plot it with
tkplot(), adjust the vertex positions and then get the new coordinates
with tkplot.getcoords(). But this works only if you have a couple of
graphs of course.

Best,
Gabor

On Tue, Apr 14, 2009 at 12:26 PM, Tom Backer Johnsen
<address@hidden> wrote:
Gabor:

Your example was very nice, but when reading the graph it failed.  I suspect
the error is in read.graph, but as far as I can see from the documentation,
there are no arguments to tell the function that the graph is signe either.
 I used the following commands in R:

library(igraph)
g <- read.graph (file="First.net", format="pajek")
g <- as.directed (g)
E(g)$curved <- is.mutual(g)
# -1 edges are dashed
E(g)$lty <- ifelse( E(g)$sign > 0, 1, 2)
# A nice layout
coords <- layout.fruchterman.reingold(g)
plot(g, layout=coords)

And the First.net file looks like this:

*NETWORK First.net; 14.04.2009 / 09:46:56
*Vertices 10
1 "S65"
2 "S29"
3 "S04"
4 "S75"
5 "S24"
6 "S81"
7 "S51"
8 "S78"
9 "S86"
10 "S39"
*Matrix
 0 0 0 0 0 1 0 0 0 -1
 0 0 1 1 0 1 1 0 1 0
 -1 0 0 1 0 0 1 0 1 0
 -1 1 0 0 1 1 1 0 1 0
 0 1 0 1 0 0 0 0 -1 -1
 1 -1 0 0 0 0 0 1 0 0
 0 -1 1 1 0 -1 0 0 1 0
 0 0 1 1 0 1 -1 0 1 1
 0 0 0 0 0 0 0 0 0 -1
 1 1 1 1 1 1 1 1 1 0

Tom


Tom Backer Johnsen wrote:
Thanks for the detailed response!  And fast as well.  I'll look into it.

Tom

Gábor Csárdi wrote:
Tom,

it is possible, with 0.5.2 or later versions. (Because of the curved
edges.) 0.5.2 will be on CRAN at any time, in the meanwhile it is
here:

http://cneurocvs.rmki.kfki.hu/igraph/download/igraph_0.5.2.tar.gz
http://cneurocvs.rmki.kfki.hu/igraph/download/igraph_0.5.2.zip

The latter is for windows. Here is how to do it:

library(igraph)

# just to always get the same nice picture
set.seed(123)

# a small directed random graph to test
g <- random.graph.game(10, 20, type="gnm", directed=TRUE)

# signs are random, too
E(g)$sign <- sample( c(-1,1), ecount(g), replace=TRUE)

# mutual edges are curved
E(g)$curved <- is.mutual(g)

# -1 edges are dashed
E(g)$lty <- ifelse( E(g)$sign > 0, 1, 2)

# A nice layout
coords <- layout.fruchterman.reingold(g)

# And the plot
plot(g, layout=coords)

Best,
Gabor

On Tue, Apr 14, 2009 at 10:43 AM, Tom Backer Johnsen
<address@hidden> wrote:
Gentlepersons:

I would like to obtain a plot of a signed and directed graph.  The graph
is
small, 10 nodes or vertices.  Since the graph is directed, I would like
to
have a curved arrow if there are arcs in both directions, with
continuous
leines and dashed for the negative ones. After reading the graph
(containing
-1's zeroes, and +1's) I see that I can plot a directed graph using g <-
as
directed (g) and then plot (g).

Is this possible?

Tom



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help





--
+----------------------------------------------------------------+
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185                        Fax : +47-5558-9879 |
| Email : address@hidden    URL : http://www.galton.uib.no/ |
+----------------------------------------------------------------+



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help






--
+----------------------------------------------------------------+
| Tom Backer Johnsen, Psychometrics Unit,  Faculty of Psychology |
| University of Bergen, Christies gt. 12, N-5015 Bergen,  NORWAY |
| Tel : +47-5558-9185                        Fax : +47-5558-9879 |
| Email : address@hidden    URL : http://www.galton.uib.no/ |
+----------------------------------------------------------------+





reply via email to

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