score:2

Accepted answer

You could add JavaScript to the HTMLWidgets to change certain text attributes/styles...

library(networkD3)
library(htmlwidgets)

links <- data.frame(
  src = c(0, 0, 0, 1, 1, 1, 2, 2, 2),
  target = c(3, 4, 5, 3, 4, 5, 3, 4, 5),
  value = 1
)

nodes <- data.frame(name = paste0("node", 1:6))

sn <- sankeyNetwork(
  Links = links,
  Nodes = nodes,
  Source = 'src',
  Target = 'target',
  Value = 'value',
  NodeID = 'name',
  fontSize = 16,
  width = 600,
  height = 300,
  margin = list("left" = 100)
)

sn <- onRender(
  sn,
  '
  function(el,x) {
    d3.select(el)
      .selectAll(".node text")
      .attr("text-anchor", "middle")
      .style("writing-mode", "vertical-rl")
      .style("text-orientation", "upright");
  }
  '
)

sn

enter image description here


Related Query