Default color used in "networkD3" package

We can use the scales package to extract default colors used by ggplot2.
To get the discrete colors used in ggplot2 for 9 levels. The following code can be used

I was wondering similar to the above approach if there is a way to extract the default colors used by the "networkD3" package in R.

Most of the functions in networkD3 use D3v4's d3.schemeCategory20 color palette by default. Finding the documentation for that is a bit difficult nowadays because d3.schemeCategory20 has been removed from D3v5+, and it seems they don't like to encourage its use anymore.

The easiest way to get the list as it is is to open a webpage that has D3v4 loaded (e.g. an htmlwidget created by networkD3), open it in a web browser, and use the developer tools to open a JavaScript console and run d3.schemeCategory20, which will give you...

0 "#1f77b4"
1 "#aec7e8"
2 "#ff7f0e"
3 "#ffbb78"
4 "#2ca02c"
5 "#98df8a"
6 "#d62728"
7 "#ff9896"
8 "#9467bd"
9 "#c5b0d5"
10 "#8c564b"
11 "#c49c94"
12 "#e377c2"
13 "#f7b6d2"
14 "#7f7f7f"
15 "#c7c7c7"
16 "#bcbd22"
17 "#dbdb8d"
18 "#17becf"
19 "#9edae5"

If you wanna get closer to the source, you can load/download and search for: "var category20".

Thanks @cjyetman for pointing this out!

@gtmbini if you want to stay closer to the grammar-of-graphics provided by ggplot, you should take a look at ggsankey by David Sjoberg, which I became aware of recently. Nevertheless for awesome Sankey plots network3D is my preference for quick and complex networks. I find myself using ggsankey when I need more control to position the nodes.

Have a look, JW

Thank you for your suggestion.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.