Sebastián
Sebastián

Reputation: 195

How can I plot igraph community with colors according to attributes?

The colors are defined by community attributes, instead vertex attributes. I need both: changing the colors of the vertex according to some vertex characteristics, and coloring the polygons around the communities.

g <- sample_gnm(15, 45) %>%
  set_vertex_attr("att", value = rep(1:3,c(6,4,5)))
wc <- walktrap.community(g)
layout <-layout.fruchterman.reingold(g)
plot(wc, g, layout=layout, vertex.label=NA, vertex.size=10, vertex.color=V(g)$att,  edge.arrow.size=.2)

Upvotes: 2

Views: 871

Answers (1)

G5W
G5W

Reputation: 37621

What you tried to set the vertex color vertex.color=V(g)$att makes sense, but unfortunately does not work when plotting communities. Instead, use col=V(g)$att to set the vertex color. If you need to change the color for the polygons, use mark.color.

plot(wc, g, layout=layout, vertex.label=NA, mark.col=rainbow(5, alpha=0.3),
    vertex.size=10, col=V(g)$att,  edge.arrow.size=.2)

Plot of community grapg

Upvotes: 3

Related Questions