Using igraph in R, I’m quoting from the manual v1.5.0, page35:
The first column of vertices is assumed to contain symbolic vertex names, this will be added to the graphs as the ‘name’ vertex attribute. Other columns will be added as additional vertex attributes.
I’m reproducing the example from manual page 36:
actors <- data.frame(
name = c(
"Alice", "Bob", "Cecil", "David",
"Esmeralda"
),
age = c(48, 33, 45, 34, 21),
gender = c("F", "M", "F", "M", "F")
)
relations <- data.frame(
from = c(
"Bob", "Cecil", "Cecil", "David",
"David", "Esmeralda"
),
to = c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
same.dept = c(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE),
friendship = c(4, 5, 5, 2, 1, 1), advice = c(4, 5, 5, 4, 2, 3)
)
g <- graph_from_data_frame(relations, directed = TRUE, vertices = actors)
All these vertices have attribute names like: name, age, gender. The others are edge attributes. For some reason, I cannot retrieve the attribute names using the following function:
graph_attr_names(g)
# character(0)
But this function gives you the vertex attributes from the 2nd dataframe ‘actors’.
vertex_attr_names(g)
# [1] "name" "age" "gender"
In the graph object I can access vertex attributes:
V(g)$name
# [1] "Alice" "Bob" "Cecil" "David" "Esmeralda"
But after clustering:
cl <- cluster_infomap(g)
the attributes seem to disappear, except for name
which is renamed to names
. So this works:
cl$names
# [1] "Alice" "Bob" "Cecil" "David" "Esmeralda"
But I cannot access age
.
cl$age
# NULL
A function call returns the vertex names
for all communities but not the other attributes.
communities(cl)
# $`1`
# [1] "Alice" "Bob" "Cecil" "David" "Esmeralda"
How can I access the additional vertex attributes mentioned in the manual? I’d like to see the age
and gender
for every community. Thank you very much for any information on this!