visNetwork中缩放后的节点中如何包含标签? [英] How have labels inside the scaled nodes in visNetwork?
问题描述
在 visNetwork 中,默认情况下,文本不在节点内,而是显示在它下面:
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%")
似乎解决此问题的唯一方法是将set shape
属性设置为circle
:
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%")
问题是,如您在上图中所看到的,现在使用value
属性在圆比例缩放节点内具有标签不起作用.
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:可惜,没有visNetwork标签!
PS: What a pity, there is no visNetwork tag!
推荐答案
我找到了解决此错误的棘手方法.设置font.size
而不是value
属性可以正常工作.您需要对其进行缩放以获得最佳可视化效果.例如,我将其缩放10倍:
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%")
这篇关于visNetwork中缩放后的节点中如何包含标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!