我使用networkD3
包在 R 中创建了一个 Sankey 图,我想将其保存为静态图像,使用代码而不是单击“导出”->“另存为图像...”。
我尝试过的当前代码(以这个桑基图为例)是:
library(networkD3)
URL <- paste0(
"https://cdn.rawgit.com/christophergandrud/networkD3/",
"master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
# Plot
jpeg( filename = "Sankey.jpg", width = 4000, height = 4000)
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
units = "TWh", fontSize = 12, nodeWidth = 30)
dev.off()
但是,当我打开图像时,我得到的只是一个空白的白色框。