最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - plot from sankeyNetwork in networkD3 does not show output (issue is not number of unique nodes) - Stack Overflow

programmeradmin3浏览0评论

There are already many questions about this on this site, e.g. this one: plot from sankeyNetwork in networkD3 does not show output neither generates any warning/error in R but my issues seems to be something else than what is written in the accepted answer.

The curious thing is that this problem (no plot, but no error message either) already appears in below example that is copied literally from the internet:

nodes = data.frame("name" = 
                     c("Node A", # Node 0
                       "Node B", # Node 1
                       "Node C", # Node 2
                       "Node D"))# Node 3
links = as.data.frame(matrix(c(
  0, 1, 10, # Each row represents a link. The first number
  0, 2, 20, # represents the node being conntected from. 
  1, 3, 30, # the second number represents the node connected to.
  2, 3, 40),# The third number is the value of the node
  byrow = TRUE, ncol = 3))
names(links) = c("source", "target", "value")
sankeyNetwork(Links = links, Nodes = nodes,
              Source = "source", Target = "target",
              Value = "value", NodeID = "name",
              fontSize= 12, nodeWidth = 30)

source: /

I assume that the person who wrote that website did get their plot, but on my computer it is not working. I hope there is a simple explanation.

Edit:

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_Europe.utf8  LC_CTYPE=English_Europe.utf8    LC_MONETARY=English_Europe.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Europe.utf8    

time zone: Europe/Amsterdam
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] networkD3_0.4

loaded via a namespace (and not attached):
 [1] digest_0.6.35     igraph_2.1.4      fastmap_1.2.0     xfun_0.44         magrittr_2.0.3   
 [6] knitr_1.46        pkgconfig_2.0.3   htmltools_0.5.8.1 rmarkdown_2.27    lifecycle_1.0.4  
[11] cli_3.6.2         compiler_4.4.0    rstudioapi_0.16.0 tools_4.4.0       evaluate_0.23    
[16] yaml_2.3.8        rlang_1.1.3       jsonlite_1.8.8    htmlwidgets_1.6.4

There are already many questions about this on this site, e.g. this one: plot from sankeyNetwork in networkD3 does not show output neither generates any warning/error in R but my issues seems to be something else than what is written in the accepted answer.

The curious thing is that this problem (no plot, but no error message either) already appears in below example that is copied literally from the internet:

nodes = data.frame("name" = 
                     c("Node A", # Node 0
                       "Node B", # Node 1
                       "Node C", # Node 2
                       "Node D"))# Node 3
links = as.data.frame(matrix(c(
  0, 1, 10, # Each row represents a link. The first number
  0, 2, 20, # represents the node being conntected from. 
  1, 3, 30, # the second number represents the node connected to.
  2, 3, 40),# The third number is the value of the node
  byrow = TRUE, ncol = 3))
names(links) = c("source", "target", "value")
sankeyNetwork(Links = links, Nodes = nodes,
              Source = "source", Target = "target",
              Value = "value", NodeID = "name",
              fontSize= 12, nodeWidth = 30)

source: https://www.displayr/sankey-diagrams-r/

I assume that the person who wrote that website did get their plot, but on my computer it is not working. I hope there is a simple explanation.

Edit:

> sessionInfo()
R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_Europe.utf8  LC_CTYPE=English_Europe.utf8    LC_MONETARY=English_Europe.utf8
[4] LC_NUMERIC=C                    LC_TIME=English_Europe.utf8    

time zone: Europe/Amsterdam
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] networkD3_0.4

loaded via a namespace (and not attached):
 [1] digest_0.6.35     igraph_2.1.4      fastmap_1.2.0     xfun_0.44         magrittr_2.0.3   
 [6] knitr_1.46        pkgconfig_2.0.3   htmltools_0.5.8.1 rmarkdown_2.27    lifecycle_1.0.4  
[11] cli_3.6.2         compiler_4.4.0    rstudioapi_0.16.0 tools_4.4.0       evaluate_0.23    
[16] yaml_2.3.8        rlang_1.1.3       jsonlite_1.8.8    htmlwidgets_1.6.4
Share edited Mar 7 at 13:13 zx8754 56.4k12 gold badges126 silver badges226 bronze badges Recognized by R Language Collective asked Mar 7 at 11:46 VincentVincent 7432 gold badges7 silver badges20 bronze badges 2
  • 3 This code runs perfectly fine on my end. You can check your package version packageVersion("networkD3"), it should be ‘0.4’. Can you give us a quick sessionInfo()? – Tim G Commented Mar 7 at 12:11
  • 2 This may also be due to a known issue with R 4.4.0. You can either download the patched version or upgrade your R version outright and it should work. – cristian-vargas Commented Mar 7 at 15:27
Add a comment  | 

1 Answer 1

Reset to default 0

As predicted by  cristian-vargas in the comments, upgrading to R version 4.4.3 fixed the issue!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论