My Sankey Diagram( Has zero value but appear that it has)

42 views Asked by At

My Sankey Diagram input looks like this:

Source Target Value
0 0 0
0 1 0
0 2 0
0 3 0
1 0 23324
1 1 5465
1 2 3234
1 3 2423423

and so on ....

If you observe my first source (Node is 0) because it doens't exist in the first place! I'm trying to visualize the land use land cover changes with the sankey diagram but R keeps thinking that my Node 0 has value but it doens't have any. I just kept it there to keep it equal. Any idea how to remove it. It has no value.

1

There are 1 answers

0
GRowInG On

Here is a dplyr solution to deleting the initial rows with zero values from your input data - assuming that it is a data.frame:

library (dplyr) 

# Delete the initial 4 rows and 
# keep everything from row 5 onwards
newdf <- yourdf %>% slice (5:n())

The first argument/number in slice represents the first row you'd like to keep. n() just means selecting everything between the first row you'd like to keep and the last row of your data.frame.

Make sure that the package your working with to generate the diagram does not require the source variable to start from 0. If that's the case you might want to renumber it using rep and seq arguments, for instance.