Can we vary the text size along with node size in R-igraph?

6.4k Views Asked by At

Can we vary the text size along with node size in R-igraph? If yes, what attribute we can use? Any example?

(By text I mean the node Name)

Network using iGraph

For example I have plotted above network using igraph function as follows:

plot.igraph(net,vertex.label=V(net)$name,layout=layout.fruchterman.reingold,
            edge.color="black",edge.width=Eweight,edge.curved=F)

If we look at label corresponding to each node, each has same size. I want to vary this label size according to their corresponding Node size. e.g. size("w1") > size("w5") > size("w6") and so on.

1

There are 1 best solutions below

0
On

You can create reproducible example using a data.frame

library(igraph)
dat  <- data.frame(name=c("Alice", "Bob", "Cecil"),age=c(48,33,45))
g<-graph.data.frame(dat)

Then change the change the some attributes

 V(g)$label.cex <- seq(0.5,5,length.out=6)         ## text size
 V(g)$size      <- seq(10,60,length.out=6)         ## circle size proportional to text size

final plot

plot(g, vertex.label = V(g)$name,
     vertex.shape="circle",
     vertex.color="red"
 )

enter image description here