score:0

As already mentioned in the comments, you might want to give networkD3 a shot.

Here is an example based on the sample data you provide.

# Create nodes and links data.frames
nodes <- data.frame(name = unique(unlist(hc_dat[, 1:2])))
links <- data.frame(
    source = match(hc_dat$from, nodes$name) - 1,
    target = match(hc_dat$to, nodes$name) - 1,
    value = hc_dat$N)

# Draw a Sankey diagram
library(networkD3)
sankeyNetwork(
    Links = links, Nodes = nodes,
    Source = "source", Target = "target", Value = "value", NodeID = "name",
    fontSize = 16, fontFamily = "sans-serif", nodeWidth = 30, nodePadding = 30)

enter image description here

score:3

Sankey from A->B and from B->C can be done by re-defining your underlying data:

 hc_dat <- data.frame(from = c("A", "B"), 
                 to = c("B", "C"), N = c(7, 5))

Similarly, you can define node from A->C

 hc_dat <- data.frame(from = c("A", "B", "A"), 
                 to = c("B", "C", "C"), N = c(5, 5, 7))

This does not render a nice plot, though.


Related Query

More Query from same tag