2

I'd like to make a sankey plot in R and save it as a non-interactive picture (e.g. jpeg/png). However I'd like to show the numbers or frequencies of the flows by default, without hovering over the flows in R.

Is there any way to do this? I couldn't find this specific question on stackoverflow or any other site. I'm using networkD3 now, as I like the layout.

This is an example of my code:

    library("networkD3")

links2 <- data.frame(
  source=c("d1", "d1", "d1", "d1", "d1", 
           "d2", "d2", "d2", "d2", 
           "d3", "d3", "d3", 
           "d4", "d4", "d4", "d4", "d4", 
           "d5", "d5", "d5", 
           "d6", "d6", "d6"), 
  target=c("h2","h3", "h4", "h5", "h6",
           "h2", "h1", "h3", "h4", 
           "h3", "h1", "h2", 
           "h4", "h1", "h2", "h3", "h5", 
           "h5", "h1", "h6", 
           "h6", "h1", "h3"), 
  value=c(7, 272, 322, 353, 18,
          219, 22, 8, 30, 
          1686, 168, 84,
          936, 180, 65, 100, 80, 
          634, 163, 12,
          406, 80, 6
  )
)

nodes2 <- data.frame(
  name=c(as.character(links2$source), 
         as.character(links2$target)) %>% unique()
)

links2$IDsource <- match(links2$source, nodes2$name)-1 
links2$IDtarget <- match(links2$target, nodes2$name)-1

nw <- sankeyNetwork(Links = links2, Nodes = nodes2,
                            Source = "IDsource", Target = "IDtarget",
                            Value = "value", NodeID = "name", 
                            sinksRight=F, margin = T)
nw

Example Sankey plot networkD3

Jajo123
  • 75
  • 4

0 Answers0