0

I am here seeking your help. I have a problem with plotting sankey diagram with networkD3 package.

here is the data: https://docs.google.com/spreadsheets/d/1nc2RVGulnjXjN4YLVdYka_sdcmww-W6kZcgRJaJOw0s/edit?usp=sharing

In this dataset, I have 226 sources and targets. If I only plot, for example, 40 sources and targets, the plot is what I am looking for:

test <- data                 #data can be downloaded from the google shared link#
test [test[c(1: 40),]        #select the first 40#
node <- data.frame(
  name=c(as.character(test$source), 
         as.character(test$target)) %>% unique()
)
test$IDsource <- match(test$source, node$name)-1 
test$IDtarget <- match(test$target, node$name)-1
sankeyNetwork(Links = test, Nodes = node,
              Source = "IDsource", Target = "IDtarget",
              NodeID = "name", Value = "value",
              sinksRight = FALSE)

enter image description here

however, if I plot all of them, it looks like this:

test <- data 
node <- data.frame(
  name=c(as.character(test$source), 
         as.character(test$target)) %>% unique()
)
test$IDsource <- match(test$source, node$name)-1 
test$IDtarget <- match(test$target, node$name)-1
sankeyNetwork(Links = test, Nodes = node,
              Source = "IDsource", Target = "IDtarget",
              NodeID = "name", Value = "value", 
              sinksRight = FALSE)

enter image description here

I am not familiar with the syntax of networkD3, is there a way to condense the targets (e.g., ampibian, scaled_reptile, bird, mammal), and also without overlapping. Thanks so much.

I have not tried other things.

Young
  • 1
  • 1

0 Answers0