R interface: square vertices kill vertical edges

Bug #517635 reported by Keith Ponting
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
igraph
Fix Released
High
Unassigned

Bug Description

igraph looks extremely useful, thankyou, but I have come across an oddity in version 0.5.3 (R 2.10.0 patched, Windows Vista).

With the following commands the intention is that there should be vertical arrows between the layers, but they do not appear (see attached PDF). Investigating this, I found that the square.shift function in plot.shapes.R needs a small fix given below.

nodes <- data.frame(name=c("Spp","Sp","Sc","Sn","Snn",
                        "Vpp","Vp","Vc","Vn","Vnn",
                        "Opp","Op","Oc","On","Onn"),
                    color=c(rep(NA,10),NA,rep("grey",3),NA),
                    frame.color=rep(c(NA,rep("black",3),NA),3),
                    shape=c(rep("square",10),rep("circle",5)),
                    x=rep(-2:2/2,3),
                    y=rep(1:-1,each=5))
labels <- c(NA,expression(S[t-1]),expression(S[t]),expression(S[t+1]),NA,
            NA,expression(V[t-1]),expression(V[t]),expression(V[t+1]),NA,
            NA,expression(O[t-1]),expression(O[t]),expression(O[t+1]),NA)
nn <- as.character(nodes$name)
edges <- data.frame(from=c(nn[1:4],nn[2:4],nn[6:9],nn[7:9]),
                    to=c(nn[2:5],nn[7:9],nn[7:10],nn[12:14]),
                    lty=rep(c(3,1,1,3,1,1,1),2),
                    color=rep("darkgrey",14))
gg <- graph.data.frame(edges,directed=TRUE,vertices=nodes)
V(gg)$label <- labels
plot(gg,layout=as.matrix(subset(nodes,select=c(x,y))))

One workaround appears to be to use any of "csquare", "rectangle" or "crectangle" as the shape instead of "square".

The problem appears to be in the following in square.shift from plot.shapes.R
      m <- (y0-y1)/(x0-x1)
      l <- cbind((-vsize+m*x1)/m , y1-vsize,
                 x1-vsize , y1-vsize*m,
                 (vsize+m*x1)/m , y1+vsize,
                 x1+vsize , y1+vsize*m )
which causes the first and fifth elements to be NaN when x0==x1. Changing this to:
      l <- cbind(x1-vsize/m , y1-vsize,
                 x1-vsize , y1-vsize*m,
                 x1+vsize/m , y1+vsize,
                 x1+vsize , y1+vsize*m )
seems to fix the problem.

Revision history for this message
Keith Ponting (k-ponting) wrote :
Changed in igraph:
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote :

Thanks for another amazing bug report! Fixed in revision #1575 (0.5-main) and #1764 (0.6-main).

Changed in igraph:
status: Confirmed → Fix Released
Revision history for this message
Gábor Csárdi (gabor.csardi) wrote : Continue on github

The development of igraph has moved to github, so please do not comment on this bug here. You are of course welcome to comment on github, here:
https://github.com/igraph/igraph/issues/57

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.