Search code examples
rigraphnamesvertex

how to set position of vertex names in igraph network


I need to set the position of vertex labels inside or right next to them. Which parameter should i change in plot to change that?

i've tried to change vertex.label.cex and vertex.label.dist parameters but labels still located in the corner of the plot and look messy.

plot(g, 
 vertex.color= "yellow",
 vertex.size = degree(g)*0.3,
 vertex.label=names,
 vertex.label.cex = degree(g)/1000,
 edge.width= 0.5,
 vertex.label.dist=0.1)

Solution

  • You had the right idea with vertex.label.dist. You just used too small a value.

    Since you did not provide your graph, I will illustrate with a random graph (and some modifications to your plot statement to match this graph).

    library(igraph)
    
    set.seed(1234)
    g = erdos.renyi.game(15, 0.2)
    plot(g)
    
    par(mfrow=c(1,2))
    set.seed(4321)
    plot(g, 
     vertex.color= "yellow",
     vertex.size = degree(g),
     edge.width= 0.5,
     vertex.label.dist=0.1,
     margin=-0.2, 
     main="vertex.label.dist=0.1")
    
    set.seed(4321)
    plot(g, 
     vertex.color= "yellow",
     vertex.size = degree(g),
     edge.width= 0.5,
     vertex.label.dist=1,
     margin=-0.2,
     main="vertex.label.dist=1")
    

    Graph with unshifted and shifted labels

    Notice that with the larger value of vertex.label.dist the labels are visibly offset.