I'm using in Visual Studio R Tools (CRAN R 3.3.2) igraph 1.0.0 contract function to merge some vertices in a graph using vertex.attr.comb = "first"
.
It works ok for numeric attributes but for character attributes the attribute is changed to a list. One of the attributes is shape.
After contract tkplot
fails, because V(g)$shape
is a list.
I have a graph g with attributes:
data.frame(a = vertex_attr_names(g), b = unlist(lapply(vertex_attr_names(g), function(x) mode(vertex_attr(g, x, V(g))))))
a b
1 Period character
2 Organization character
3 EmplPermanence character
4 EmplType character
5 FullParttime character
6 JobClassification character
7 Gender character
8 Age character
9 Education character
10 PersonnelCount numeric
11 source character
12 index numeric
13 graphlevel numeric
14 kind character
15 name character
16 value numeric
17 layer numeric
18 color character
19 type logical
20 status character
21 aka character
22 completed logical
23 branch numeric
24 branchname character
25 shape character
26 size numeric
I use
test <- contract(g, NewVertices, "first")
and look at the attributes:
data.frame(a = vertex_attr_names(test), b = unlist(lapply(vertex_attr_names(test), function(x) mode(vertex_attr(test, x, V(test))))))
a b
1 Period list
2 Organization list
3 EmplPermanence list
4 EmplType list
5 FullParttime list
6 JobClassification list
7 Gender list
8 Age list
9 Education list
10 PersonnelCount numeric
11 source list
12 index numeric
13 graphlevel numeric
14 kind list
15 name list
16 value numeric
17 layer numeric
18 color list
19 type list
20 status list
21 aka list
22 completed list
23 branch numeric
24 branchname list
25 shape list
26 size numeric
27 round numeric
When I try to use tkplot on test:
lbl <- vertex_attr(test, "index", V(test))
lbl <- unlist(lbl)
> tkplot(test, layout = coord, vertex.label = lbl,
+ vertex.label.family = "sans", vertex.label.cex = 0.8,
+ edge.width = 2, edge.arrow.size = 0.5, edge.arrow.width = 0.5)
Error in as.tclObj(x, drop = TRUE) : cannot handle object of mode 'list'
I haven't found my way around this yet. Can anybody help?