带有 networkD3 包的 Sankey 图 miximises CPU 用法并且不显示图表

Sankey Diagram with networkD3 package miximises CPU usage and does not show the diagram

大多数时候,我尝试在 R 中绘制桑基图,我的 CPU 已最大化,但图表未显示。有谁知道这可能是什么原因造成的?我的电脑配备 i7-7600U CPU @ 2.80GHz 2.90GHZ 还不错。为了让 CPU 再次下降,我不得不重新启动 R

例如我正在使用这个示例代码

library("networkD3")

myDf <- list(
    nodes=data.frame(name=c( "A", "B", "C", "D", "E",
                             "V", "W", "X", "Y", "Z")),
    links=data.frame(source=as.integer(c(0, 1, 2, 3, 3, 4, 4)),
                     target=as.integer(c(7, 6, 7, 8, 7, 5, 9)),
                     value =           c(1, 4, 1, 5, 1, 5, 3)
    )
)

sankeyNetwork(Links = myDf$links, Nodes = myDf$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 25, nodeWidth = 30, 
              fontFamily = "sans-serif", iterations = 0)

这可能是您的包或 R Studio 配置的问题。

尝试使用同一包 (networkD3) 中的 saveNetwork() 命令将 sankeyNetwork 保存为 HTML 文件并打开它。

例如

library("networkD3")

myDf <- list(
    nodes=data.frame(name=c( "A", "B", "C", "D", "E",
                             "V", "W", "X", "Y", "Z")),
    links=data.frame(source=as.integer(c(0, 1, 2, 3, 3, 4, 4)),
                     target=as.integer(c(7, 6, 7, 8, 7, 5, 9)),
                     value =           c(1, 4, 1, 5, 1, 5, 3)
    )
)

sk <- sankeyNetwork(Links = myDf$links, Nodes = myDf$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 25, nodeWidth = 30, 
              fontFamily = "sans-serif", iterations = 0)

saveNetwork(sk,file = "sk.html")