2

Is there a way I can feed a matrix of coordinates to the tkplot function in igraph? I've tried setting the layout argument to my matrix of coordinates but it just produces a blank plot.

I'm able to feed coordinates to plot.igraph() and produce a directed, weighted edge plot with the vertices in the places that I want them. BUT, the arrows are funky. The arrows are placed underneath the edges so that if the edge is wide enough (some of mine are), then the arrow is at least partially hidden. I've tried changing edge and arrow width but some of my edges are just weighted too much. The arrows produced in tkplot are closer to what I want.

The first plot below corresponds to the undesired arrows made with plot.igraph. Second plot is for the desired arrows from tkplot.

Arrows I don't want:

badarrows

Arrows I do want:

goodarrows

The reason I need to do one or the other, is because I'll need to make a few more of these graphs with the nodes in the exact same location, and don't want to have to keep using tkplot to hand-move the nodes around every time. I have quite a bit of them and it will also be impossible to get them in exactly the same position as before.

Hopefully this is specific enough. This is my first time posting, so please let me know what other information I should include. I've tried giving tkplot coordinates on R 2.15 and on a machine running 2.11, as well as with igraph package 0.5.5 and igraph 0.6.5.

Truly sorry to waste time if this is out there somewhere. I've spent a while looking as well as trying to put heads together with my grad PI to figure it out and we've been hitting dead ends for a few days now. Thank you for any feedback.

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53

1 Answers1

0

Unfortunately it is not possible to modify how the arrows look, and I agree that this sucks, especially because they are ugly.

To be a bit more constructive, you could use tkplot() to do the plots, you can actually automate saving them into files, with some tricks and using an internal igraph function. Here is an example below. Is this good enough?

library(igraph)
set.seed(1)
g <- graph.star(10, center=10) %u% graph.ring(9, directed=TRUE)
E(g)$width <- sample(1:10, ecount(g), replace=TRUE)
lay <- layout.auto(g)

id <- tkplot(g, layout=lay)
tkp <- igraph:::.tkplot.get(id)
tkpostscript(tkp$canvas, file="/tmp/output.eps")
tkplot.close(id)

plot

Gabor Csardi
  • 10,705
  • 1
  • 36
  • 53
  • Thanks for responding! Hm..well, part of the problem is that I need the vertices to be in exactly the position I have them. I have 61 of them and I've laid out their locations to correspond to where they occurred on a spatial map. Is there a way I can convert my matrix of coordinates to a layout object and use that in the layout argument in tkplot()? I've tried, unsuccessfully, using 'layout()' – Sara Decker Mar 24 '13 at 04:26
  • I am not sure what you mean by using `layout()`, but you can just use your coordinates as the layout argument of the `tkplot()` function. Just like in my example above, but use your precalculated coordinates instead of `lay`. `plot()` and `tkplot()` works exactly the same way in this respect. – Gabor Csardi Mar 24 '13 at 20:42
  • Awesome, thanks Gabor! It worked once I set: layout=my.layout %*% diag(c(1,-1)). Before I was just setting it to my.layout and it was just producing a blank plot. Thanks for all your help! – Sara Decker Mar 26 '13 at 17:27