[igraph] changing vertex shape according to vertex characteristics

603 views
Skip to first unread message

Meenakshi Parameshwaran

unread,
Apr 3, 2013, 4:38:41 PM4/3/13
to igrap...@nongnu.org
Dear all,

I am new to igraph and to R. I have a simple problem I hope you can help with. i am trying to visualise a classroom network and I want the vertices to have different colours by ethnic minority/majority background, and different shapes by gender. The colours work ok, but I can't make the shapes change.

#set color of vertex attribute according to ethmin
V(graph1)$color <- ifelse(ethmin4 == 1, "red", "blue")
V(graph1)$color

#set shape of vertex attribute according to gender
V(graph1)$shape <- ifelse(female4 == 1, "circle", "square")
V(graph1)$shape

myLayout <- layout.fruchterman.reingold(graph1)

plot.igraph(graph1,
            vertex.color = V(graph1)$color,
            vertex.shape = V(graph1)$shape,
            vertex.size = 15,
            edge.color = "black",
            edge.arrow.size = 0.05,
            layout = myLayout
)

But this doesn't work, and I get the following error:

Error in igraph.check.shapes(params("vertex", "shape")) : 
  Bad vertex shape(s): NA.

When I type V(graph1)$shape, I get the following so I think that has loaded correctly. And I think my shape names are correct.

 [1] "square" "circle" "square" "square" "circle" "square" "circle" "square" "circle" "square"
[11] "circle" "circle" "square" "square" "circle" "circle" "circle" NA       "square" "circle"
[21] "square"

Any ideas?

Thanks very much,
Meena

Tamás Nepusz

unread,
Apr 3, 2013, 4:43:35 PM4/3/13
to Help for igraph users
> #set shape of vertex attribute according to gender
> V(graph1)$shape <- ifelse(female4 == 1, "circle", "square")
If you have an NA value somewhere in the female4 vector, this will introduce NA values in the shape vector as well. E.g.:

> female4 <- c(1, 0, NA)
> ifelse(female4 == 1, "circle", "square")
[1] "circle" "square" NA

So, the solution is to get rid of the NA values from your female4 vector.

--
T.
_______________________________________________
igraph-help mailing list
igrap...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/igraph-help

Meenakshi Parameshwaran

unread,
Apr 3, 2013, 4:48:29 PM4/3/13
to Help for igraph users
Dear Tamas,

Thanks for your advice here. I had NA values in my ethmin4 vector as well, but this did not seem to affect the colouring of the vertices. But I guess it affects the shapes. So I will try this and see.

Many thanks,
Meena

Tamás Nepusz

unread,
Apr 3, 2013, 4:50:48 PM4/3/13
to Help for igraph users
> Thanks for your advice here. I had NA values in my ethmin4 vector as well, but this did not seem to affect the colouring of the vertices. But I guess it affects the shapes. So I will try this and see.
Maybe the colors are not affected because igraph manages to interpret "NA" as a color; I don't know the details but maybe it is interpreted as "no fill color". However, there is no similar interpretation for "NA" as a shape.

--
Tamas
Reply all
Reply to author
Forward
0 new messages