2016-09-24 79 views
5

visNetwork,默認文字不進去的節點,而是在下方顯示:visNetwork中縮放節點內的標籤如何?

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%") 

enter image description here

好像來解決這個問題的唯一方法是使用設置shape屬性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%") 

enter image description here

問題在於,如上圖所示,現在使用value屬性的圓縮放節點內的標籤不起作用。

所以問題是如何同時擁有兩個選項(「縮放」和「文本內部」)?

PS:真遺憾,沒有visNetwork標籤!

+0

你會建議額外的標籤嗎? – Woeitg

回答

4

我發現了一個棘手的方法來解決這個錯誤。設置font.size而不是value屬性工作正常。您需要將其縮放以獲得最佳可視化效果。比如我它的規模大10倍:

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%") 

enter image description here

+0

還沒有其他解決方案嗎? – skan

1

我找到了另一種方式,添加標籤上的機器人兩側空間。
這將保持所有字體相同的大小。

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%") 

enter image description here

如果標籤的長度是不是你可能想嘗試其他條件都相同。