r - Why igraph plot warns that "number of items to replace is not a multiple of replacement length"? -


i have graph many edges between 2 nodes. when plot it, warning don't understand in context.

this works fine:

library(igraph) gg <- graph.empty(n=0, directed=true) gg <- gg + vertex("10501") gg <- gg + edge("10501", "10501") gg <- gg + edge("10501", "10501") plot(gg) 

but same graph 1 more edge gives warning:

gg <- graph.empty(n=0, directed=true) gg <- gg + vertex("10501") gg <- gg + edge("10501", "10501") gg <- gg + edge("10501", "10501") gg <- gg + edge("10501", "10501") plot(gg) 

i fail see reason. why warning?

searching igraph package source line giving warning, seems culprit function autocurve.edges in plot.common.r:

autocurve.edges <- function(graph, start=0.5) {   cm <- count.multiple(graph)   el <- apply(get.edgelist(graph, names=false), 1, paste, collapse=":")   ord <- order(el)   res <- numeric(length(ord))    p <- 1   while (p <= length(res)) {     m <- cm[ord[p]]     idx <- p:(p+m-1)     if (m==1) {       r <- 0     } else {       r <- seq(-start, start, length=m)     }     res[ord[idx]] <- r     p <- p + m   }   res } 

according ?igraph.plotting (and package source) autocurve.edges function called default determine how curve edges:

by default vector specifying curvatire calculated via call autocurve.edges function. function makes sure multiple edges curved , visible. parameter ignored loop edges.

from in igraph.plot, can see function called, being passed whole graph:

curved             <- params("edge", "curved") if (is.function(curved)) { curved <- curved(graph) } 

this source of warnings on problematic graph:

autocurve.edges(gg) # [1] -0.5 -0.5  0.0 # warning messages: # 1: in res[ord[idx]] <- r : #   number of items replace not multiple of replacement length # 2: in res[ord[idx]] <- r : #   number of items replace not multiple of replacement length 

to delve why we're seeing these issues, first thing function call count.multiple, returns number of times each edge repeated. in offending graph:

count.multiple(gg) # [1] 1.5 1.5 1.5 

instead of returning c(3, 3, 3) (since looping edge repeated 3 times), it's returning c(1.5, 1.5, 1.5). though don't see mention of in ?count.multiple, happening because count of edge divided 2 if loop (aka edge node itself), due following line in igraph_count_multiple structural_properties.c file in igraph package source:

/* loop edges, divide result 2 */ if (to == from) vector(*res)[i] /= 2; 

the fact warnings generated due bug -- autocurve.edges expecting c(3, 3, 3) instead got c(1.5, 1.5, 1.5) count.multiple due loop edges. think autocurve.edges reimplemented in pure r using like:

autocurve.edges <- function(graph, start=0.5) {   el <- apply(get.edgelist(graph, names=false), 1, paste, collapse=":")   ave(rep(na, length(el)), el, fun=function(x) {     if (length(x) == 1) {       return(0)     } else {       return(seq(-start, start, length=length(x)))     }   }) } 

further, think documentation of count.multiple should updated mention special handling of loop edges.

in meantime, think solution in case manually specify curvature parameter avoid warnings:

plot(gg, edge.curved=false) 

update: submitted pull request rigraph project , merged dev branch of r igraph project: https://github.com/igraph/rigraph/pull/80


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -