问题
Using the code below I can generate a plot of the communities in the 'karate club' example provided by igraph (see first image).
library(igraph)
karate <- make_graph("Zachary")
wc <- cluster_walktrap(karate)
plot(wc, karate)
How can I add a text label 'near' each of the communities? For this example, say I want to call the 5 different communities "Community X" (X = 1:5). Ideally, the code would place the text labels on the 'outside' of the colored community polygons to create a clear graph (by placing the labels on the furthest xy coord from the center of the graph for each polygon). (See second image)
I've looked at this post, but the only suggestion is to add the labels manually.
Any ideas on how to add the text labels with code? Is it possible to 'get' the xy coords of the community polygons and add the text labels that way? (Not sure if this should be a new question or a comment on the linked post's answer - let me know as I'm new to this).
Thanks a lot!
EDIT: Based on the comment below, I identified the following code that seems to be drawing the polygons for each of the groups/communities:
params <- i.parse.plot.params(graph, list(...))
#...
layout <- params("plot", "layout")
#....
for (g in seq_along(mark.groups)) {
v <- V(graph)[mark.groups[[g]]]
#...
igraph.polygon(layout[v, , drop = FALSE], vertex.size = vs,
expand.by = mark.expand[g]/200, shape = mark.shape[g],
col = mark.col[g], border = mark.border[g])
}
However, I can't find any information about the igraph.polygon function. I also don't know what to do with the params and 'layout[v, ,]'. Further, even if I could figure all this out, how would I change igraph's plotting function and add a text label??
来源:https://stackoverflow.com/questions/47971179/igraph-adding-text-to-community-plot