0

I have built Sankey diagrams using the package in and am wondering if there is a way to bold the text used as labels of the nodes. I have done some research and haven't found anything directly related to networkD3 in R.

CJ Yetman
  • 8,373
  • 2
  • 24
  • 56
ttucker34
  • 13
  • 3

1 Answers1

0

You can achieve some CSS formatting by injecting custom JavaScript when it renders, like...

library(networkD3)
library(jsonlite)
library(htmlwidgets)

URL <- paste0('https://cdn.rawgit.com/christophergandrud/networkD3/',
              'master/JSONdata/energy.json')
energy <- jsonlite::fromJSON(URL)

sn <- sankeyNetwork(Links = energy$links, Nodes = energy$nodes, 
                    Source = 'source', Target = 'target', Value = 'value', 
                    NodeID = 'name', units = 'TWh', fontSize = 12, 
                    nodeWidth = 30)

htmlwidgets::onRender(
  sn,
  '
  function(el) {
    d3.select(el).selectAll(".node text").attr("font-weight", "bold");
  }
  '
)
CJ Yetman
  • 8,373
  • 2
  • 24
  • 56