I want to make Sankey Graphs in R, but the networkd3 package doesn't work

146 Views Asked by At

I am trying to make Sankey graphs, however, the networkd3 package doesn't seem to work right. When I try to install it in R, the following error comes up:

Error: package or namespace load failed for ‘networkD3’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 there is no package called ‘igraph’

I am just starting out with R and can use your help to rectify this.

I am trying to make Sankey graphs using this package.

2

There are 2 best solutions below

1
DoRemy95 On BEST ANSWER

I see two solutions.

If you wish to continue using NetworkD3, you will need to install iGraph. This is what the error states. Please have a look at the documentation here: igraph-Installation.

Installing iGraph can be a little tricky depending on your machine you are working with. Another solution would be to use ggalluvial, a R library that works with ggplot to build sankey diagrams i.e. alluvial plots. You may find a nefty tutorial here: ggalluvial-tutorial

0
CJ Yetman On

Try uninstalling {networkD3} and {igraph}, and then re-installing {networkD3}...

remove.packages("networkD3")
remove.packages("igraph")
install.packages("networkD3")