[R] igraph: error when setting size and shape of vertices

Gábor Csárdi csardi at rmki.kfki.hu
Wed Feb 4 11:42:04 CET 2009


Yep, this is a bug, thanks for reporting it. It only happens with the
square shape, so until it is a corrected, a workaround is using
"rectangle" shape, with equal vertical and horizontal sizes:

g <- graph.ring(4)
g$layout <- layout.circle
V(g)$size <- seq_len(vcount(g)) * 10
V(g)$size2 <- V(g)$size

plot(g, vertex.shape="square")       # gives an error
plot(g, vertex.shape="rectangle")    #  works

I have tried this only on the not-yet-released 0.6 version, please
tell me if it does not work on 0.5.1.

Best,
Gabor

On Wed, Feb 4, 2009 at 11:26 AM,  <robbie.heremans at telenet.be> wrote:
> When the shape of all vertices is set to "square" and the size of the vertices is also set, one get following error (commands attached):
>
> Error in l[[which.min(sapply(l, function(p) (p[1] - x0)^2 + (p[2] - y0)^2))]] :
>        attempt to select less than one element
>
> Is there a way to solve this problem?
>
> Robbie
>
> ## Load the igraph package
> library(igraph)
>
> ## Create and plot a small graph
> g <- graph( c(0,1, 0,2, 1,2, 2,3), n=4, directed = FALSE)
> plot(g)
>
> V(g)$size<-c(10,15,20,30)
> plot(g) #OK
>
> V(g)$shape<-c("circle","circle","circle","square")
> plot(g) #OK
>
> V(g)$shape<-c("circle","circle","square","square")
> plot(g) #OK
>
> V(g)$shape<-c("circle","square","square","square")
> plot(g) #OK
>
> V(g)$shape<-c("square","square","square","square")
> plot(g) #Error in l[[which.min(sapply(l, function(p) (p[1] - x0)^2 + (p[2] - y0)^2))]] :
>        #attempt to select less than one element
>
> V(g)$shape<-c("square","square","circle","square")
> plot(g) #OK
>
> ## Same without changing size
> g <- graph( c(0,1, 0,2, 1,2, 2,3), n=4, directed = FALSE)
> V(g)$shape<-c("square","square","square","square")
> plot(g) #OK
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Gabor Csardi <Gabor.Csardi at unil.ch>     UNIL DGM




More information about the R-help mailing list