I'm trying to make a network graph using visNetwork package in r. I have problem trying to make my node label proportional to the node size. I know the node size is controlled by column size in nodes. But what about the label size?
One additional question. What does idToLabel do? I tried to make it TRUE or FALSE, the network graph make no difference.
Thanks a lot.
Here is the sample code.
library(visNetwork)
nodes <- data.frame(id = 1:10,
label = paste("Node", 1:10), # labels
group = c("GrA", "GrB"), # groups
value = 1:10, # size
title = paste0("<p><b>", 1:10,"</b><br>Node !</p>"), # tooltip
color = c("darkred", "grey", "orange", "darkblue", "purple"),# color
shadow = c(FALSE, TRUE, FALSE, TRUE, TRUE)) # shadow
edges <- data.frame(from = sample(1:10,8), to = sample(1:10, 8),
label = paste("Edge", 1:8), # labels
length = c(100,500), # length
arrows = c("to", "from", "middle", "middle;to"), # arrows
dashes = c(TRUE, FALSE), # dashes
title = paste("Edge", 1:8), # tooltip
smooth = c(FALSE, TRUE), # smooth
shadow = c(FALSE, TRUE, FALSE, TRUE)) # shadow
visNetwork(nodes, edges, physics=T, idToLabel=T)
According to this answer you can control the label size by setting the font.size, e.g.:
nodes <- nodes %>% mutate(font.size = (1:10)*3)
As to your second question: idtolabel is defining whether to use vertex IDs as labels or the specified node-labels (see here).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With