Show only specific labels on the network using igraph in R

I am trying to build a graph that only displays labels for specific vertices. In this case, I want to show only labels for vertices with a certain number of edges.

I read the vertices and edges in the graph object as follows:

nodes <- read.csv("path_to_file.csv") edges <- read.csv("path_to_file.csv") g <- graph_from_data_frame(edges,directed=TRUE,vertices=nodes) 

I use the following command to plot and change the width of an edge based on the number of connections (the $ rels attribute is the number of connections between two vertices):

 plot.igraph(g,vertex.size=3,vertex.label.cex=0.5,layout=layout.fruchterman.reingold(g,niter=10000),edge.arrow.size=0.15,edge.width=E(g)$rels/100) 

Is there a way to say, for example, that only vertices s> 100 with edges should have their own label? If I try to leave vertex labels in my csv files, igraph thinks they duplicate vertices.


Data examples

 nodes.csv name | org_id US Department of Energy | 70063 Environmental Protection Agency | 100000 edges.csv from | to | rels US Department of Energy | Hanford SSAB | 477 Natural Resources Defense Council | Environmental Protection Agency | 322 
+6
source share
1 answer

Try

 library(igraph) set.seed(1) g <- sample_pa(20) V(g)$label <- letters[1:20] plot(g, vertex.label = ifelse(degree(g) > 2, V(g)$label, NA)) 

to display only labels for vertices with a degree greater than 2:

enter image description here

+6
source

All Articles