# install.packages("networkD3")
library("networkD3")
concept <- c("Vulnerability", "Adaptation", "Resilience")
nodes <- data.frame(concept)
source <- c(0, 1, 0)
target <- c(1, 2, 2)
value <- c(76, 48, 42)
links <- data.frame(source, target, value)
my_color <- 'd3.scaleOrdinal() .domain(["Vulnerability", "Adaptation","Resilience"]) .range(["brown", "green" , "blue"])'
sankey_plot<- sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "value", NodeID = "concept", colourScale=my_color,
units = "Indicators", fontSize = 12,
nodeWidth = 30)
sankey_plot
In this above code, I am getting the Sankey diagram in the viwer pane. What should I do to show it in the plots pane?
I am trying to make a simple Sankey diagram, keep having it in the viewer pane, not in the plots pane to download as pdf.
networkD3 creates htmlwidgets, not plots, which are essentially mini webpages, so it will always display in the viewer pane. The viewer pane has a “Save as image” option if you want a PNG (see here). There are many possible options for exporting as a SVG here on Stackoverflow if you search for them, like this https://stackoverflow.com/a/57751023/4389763