fbreitwieser / sankeyD3

D3 Sankey Network Graphs from R
65 stars 27 forks source link

wish: option for node label color (e.g. fontColor) #13

Closed ugroempi closed 6 years ago

ugroempi commented 6 years ago

This would allow me to move node labels into colored nodes and still be readable. Being greedy, one could also have separate font options (most important: size; color might be the same) for the node labels and the node values.

Best, Ulrike

fbreitwieser commented 6 years ago

Hi Ulrike, sorry for the late answer, managed to implement something like that, now. See below:

library(sankeyD3)

# sankeyNetwork
URL <- "https://cdn.rawgit.com/christophergandrud/networkD3/master/JSONdata/energy.json"
Energy <- jsonlite::fromJSON(URL)

# Plot

Energy$nodes$font_color <- c("black", "red", "green")
Energy$nodes$font_size <- 5:10
sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              fontSize = 12, nodeWidth = 30, 
              NodeColor = "font_color",
              NodeFontColor = "font_color", NodeFontSize = "font_size")

image

ugroempi commented 6 years ago

Thank you! Best, Ulrike