I have built Sankey diagrams using the networkd3 package in r 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.
Asked
Active
Viewed 480 times
0
-
3Please create a minimum reproducible example using [reprex](https://reprex.tidyverse.org/#usage). – mindlessgreen Jun 20 '21 at 20:39
1 Answers
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