rplotlabelvertex-attributes

Display labels for desired vertices only


I only want to show labels for the vertices that have a degree greater than 50. I've tried the following code :

plot(g, vertex.label=(V(g)$id[which(degree > 50)]))

But rather than only labeling the desired vertices, it seems to relabel all vertices using only the labels for those with a degree greater than 50.

How can I display a plot that only labels the desired vertices? Or is there a way to hide the undesired labels?


Solution

  • Problem is that the length of the vertex.label vector needs to equal the number of vertices. Perhaps something like

    plot(g, vertex.label=ifelse(degree(g) > 50, V(g)$id, NA) )