In visNetwork, by default text doesn't go inside nodes, instead it appears below it:
require(visNetwork, quietly = TRUE)
nodes <- data.frame(id = 1:3, label=2014:2016 ,value=1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
Seems like the only way to solve this issue is to use set shape
property to circle
:
require(visNetwork, quietly = TRUE)
nodes <- data.frame(id = 1:3, label=2014:2016 ,value=1:3,shape='circle')
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
The problem is that, as you can see in the figure above, now with labels inside circle scaling nodes using value
property don't work.
So the question is how to have both options ("scale" and "text inside") at the same time?
PS: What a pity, there is no visNetwork tag!
I found a tricky way to solve this bug. setting up font.size
instead of value
property works fine. You need to scale it for best visualization. For instance I scale it 10 times bigger:
require(visNetwork, quietly = TRUE)
nodes <- data.frame(id = 1:3, label=2014:2016 ,font.size =(1:3)*10,shape='circle')
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
I've found another way, adding spaces on bot sides of the label.
That will keep all fonts the same size.
n <- 5L
nodes <- data.frame(id = 1:3, label=paste0(strrep(" ",n), 2014:2016,
strrep(" ",n)) ,value=1:3,shape='circle')
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
If the length of the labels is not the same you may want to try other criteria.
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