igraph-help
[Top][All Lists]

## [igraph] Re: plotting planar graphs with igraph?

 From: Gábor Csárdi Subject: [igraph] Re: plotting planar graphs with igraph? Date: Wed, 8 Dec 2010 14:14:55 +0100

```Dear Christian,

On Wed, Dec 8, 2010 at 10:07 AM, Christian Jost <address@hidden> wrote:
> Dear all,
> I currently struggle with igraph to make it do things it doesn't seem to be
> designed to do. First, my networks are actually planar graphs representing
> tunneling networks (dug by ants in 2D sand disks) that I have digitised in
> Pajek format (see example below, vertex 1 is the origin of the digging
> activity). I can read these graphs without problem with read.graph, but when
> it comes to manipulating them I encounter problems. For the moment I am
> stuck with two problems.
>
> a) plot the graph with the correct x and y coordinates (specifically, I
> tried to write a function doing that, successfully plotting vertices at the
> x,y coordinates, but I cannot extract the vertex numbers of each edge
> provided by E(g) and therefore cannot add the edges; but there may be a
> simpler way to draw such a graph).

If you have the 'x' and 'y' coordinates in the corresponding attributes, then do

plot(g, layout=cbind(V(g)\$x, V(g)\$y))

You might want to read ?igraph.plotting.

> b) I have to remove the degree-2 nodes in order to get a simpler network
> with only the bifurcations and the endpoints. I use degree(g) to detect the
> nodes with degree 2, but when I feed their identities to "delete.vertices()"
> I get as a result many disconnected vertices. This function does not seem to
> reconnect the neighbour vertices after removing the degree 2 node. Is this
> normal behaviour?

Why should it reconnect the neighbor vertices? Graphs usually
represent parts of a real system, and the relationships between them.
E.g. people and friendship in case of a social network. If we remove a
person for some particular reason, then why should we reconnect the
network? Her friends do not became friends, just because we removed
her from the network.

I agree that is some special cases it might make sense to reconnect
it, but IMHO in general it does not.

You need to write a function that does this special vertex deletion
for you. It is not very hard, just query the neighbors of the 'to be
deleted' vertices, and add edges between them, before removing the
vertices themselves.

Best,
Gabor

[...]

--