2

我绘制了一个简单的网络,visNetwork但是当我尝试保存它时,png我得到一个空图像。

png("ex.png")
require(visNetwork, quietly = TRUE)
# minimal example
nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))
visNetwork(nodes, edges, width = "100%")
dev.off()
4

1 回答 1

2

您可以将网络保存为 html,然后捕获该文件的内容:

nodes <- data.frame(id = 1:3)
edges <- data.frame(from = c(1,2), to = c(1,3))

library(visNetwork)
plot<- visNetwork(nodes, edges, width = "100%")

html_name <- tempfile(fileext = ".html")
visSave(plot, html_name)

library(webshot); #webshot::install_phantomjs() #in case phantomjs was not installed 

webshot(html_name, zoom = 2, file = "ex.png")
于 2019-06-18T18:46:10.860 回答