问题
I'm plotting a network with igraph, and I only want to display some of the vertex labels. My edgelist has 2 columns- "org" and "cand" -- in my plot how can I only display the labels for nodes in "cand" ?
I've tried to use
V(g)$label <- ifelse()
I have seen ifelse used when there's a numeric attribute associated with a vector (for example, only displaying labels > 10). I'm not sure how to use this notation for my purposes. The code below shows how I created the graph and plot-- it runs fine.
`el=read.csv(file.choose("2018_party_groups3"))
el[,"org"]=as.character(el[,"org"])
el[,"cand"]=as.character(el[,"cand"])
el=as.matrix(el)
g=graph.edgelist(el[,1:2])
a=read.csv(file.choose("2018_party_att"))
V(g)$party=as.character(a$party[match(V(g)$name,a$cand)])
b=read.csv(file.choose("2018_groups_att"))
V(g)$type=as.character(b$type[match(V(g)$name,b$org)])
V(g)$color=V(g)$type
V(g)$color=gsub("U","green",V(g)$color)
V(g)$color=gsub("Ref","orange",V(g)$color)
m <- layout_with_kk(g)
plot(g, layout=m, edge.arrow.size=.2, vertex.label.font=1,
vertex.label.cex=.7, vertex.size=6, vertex.label.color="black")`
来源:https://stackoverflow.com/questions/56284638/how-do-i-select-certain-labels-to-display-in-igraph-plot