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.com/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
As predicted by cristian-vargas in the comments, upgrading to R version 4.4.3 fixed the issue!