我使用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()
答案 0 :(得分:1)
您可以将网络另存为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")