In this post I am going to show, How to Draw sankeyNetwork diagram using R Studio. To draw this diagram, we have to use networdkD3 library and and we should install R Studio Version 1.2.1070.
Code:-
According to above code it will show the data as per the below cross tab.
Code:-
library(networkD3)
IMP <- data.frame(source = c("Colombo", "Colombo", "Colombo", "Kandy", "Kandy", "Kandy"),
target = c("Male", "Female", "Children", "Male", "Female", "Children"),
Before_value = c(4,3,7,4,1,5))
# create nodes data by determining all unique nodes found in your data
node_names <- unique(c(as.character(IMP$source), as.character(IMP$target)))
nodes <- data.frame(name = node_names)
# create links data by matching the source and target values to the index of the
# node it refers to in the nodes data frame
links <- data.frame(source = match(IMP$source, node_names) - 1,
target = match(IMP$target, node_names) - 1,
Before_value = IMP$Before_value)
sankeyNetwork(Links = links, Nodes = nodes, Source = "source",
Target = "target", Value = "Before_value")
According to above code it will show the data as per the below cross tab.
R Studio – sankeyNetwork Graph
Reviewed by Pubudu Dewagama
on
9:08:00 PM
Rating:
No comments: