0

I'm trying to create a Sankey diagram of before/afters from a survey. The categories are "Never", "Rarely", "Sometimes", "Often", and "Always". I have a total of 10 nodes because there are some circular ones so when I had 5, it made a weird looking diagram. Anyways, this code I have right now just outputs absolutely nothing, so I'm wondering if anyone who likes R knows what's up with this.

nodes = data.frame("name" = c("Always", "Often", "Sometimes", "Rarely", "Never", "Always ", "Often ", "Sometimes ", "Rarely ", "Never "))

## create edges with weights
links = as.data.frame(matrix(c(4, 8, 1, # never --> rarely with weight 1
                               4, 7, 1, # never --> sometimes with weight 1
                               4, 6, 1, # never --> often with weight 1
                               3, 9, 1, # rarely --> never with weight 1
                               2, 7, 2, # sometimes --> sometimes with weight 2
                               2, 5, 3, # sometimes--> always with weight 3
                               1, 6, 2, # often -> often with weight 2
                               1, 5, 1,  # often -->always with weight 1
                               0, 6, 1,  # always -->often with weight 1
                               0, 5, 1  # often -->always with weight 1
                               
                               ), byrow = TRUE, ncol = 3))

## set column names for links
names(links) = c("source", "target", "value")

## Create custom color list using d3 for each node
# node_color <- 'd3.scaleOrdinal() .domain([c("Always", "Often", "Sometimes", "Rarely", "Never", "Always ", "Often ", "Sometimes ", "Rarely ", "Never ")]) .range(["red", "blue", "orange", "yellow",  "pink","purple", "green", "black", "indigo",  "cyan"])'

## Draw Sankey Diagram
p = sankeyNetwork(Links = links, Nodes = nodes,
 Source = "source", Target = "target",
 Value = "value", NodeID = "name",
 fontSize = 16, nodeWidth = 40)
 #colourScale = node_color)

p
bmatt23
  • 13
  • 3

0 Answers0