fbreitwieser / sankeyD3

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

coloring individual nodes #30

Open kenneditodd opened 11 months ago

kenneditodd commented 11 months ago

Hello,

Can you show example code for selecting individual colors for nodes? The documentation has changed since the examples shown in other issues like #20 . I have tried reading this documentation but have been still failing to execute properly.

@SchmidtPaul do you have any idea? as i see you have been very helpful in addressing some issues!

SchmidtPaul commented 11 months ago

Hi @kenneditodd, I am a bit irritated: Does my example in mentioned issue no longer work for you? Because it still works for me as can be seen below.

By the way, I am currently in the process of creating {sankeyD3plus} with some small improvments. But so far I did not feel the need to improve anything about the NodeColor = argument.

library(sankeyD3)

links <- data.frame(
  source = c(0, 0, 1, 2),
  target = c(1, 2, 3, 3),
  value = c(10, 20, 10, 20),
  linkcolor = c("col1", "col1", "col2", "col2")
)

my_color <- 'd3.scaleOrdinal() .domain(["col1", "col2"]) .range(["blue", "#d12e69"])'

nodes <- data.frame(
  label = c("A", "B", "C", "D"),
  nodecolor = c("green", "green", "#E3B505", "#E3B505")
)

sankeyD3::sankeyNetwork(
  Links = links,
  Nodes = nodes,
  Source = "source",
  Target = "target",
  Value  = "value",
  NodeID = "label",
  LinkGroup = "linkcolor",
  colourScale = my_color,
  NodeColor = "nodecolor",
  numberFormat = ",.0f",
  fontFamily = "Arial",
  fontSize = 12,
  width  = 400,
  height = 300)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.


sessionInfo()
#> R version 4.3.0 (2023-04-21 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=German_Germany.utf8  LC_CTYPE=German_Germany.utf8   
#> [3] LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C                   
#> [5] LC_TIME=German_Germany.utf8    
#> 
#> time zone: Europe/Berlin
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] sankeyD3_0.3.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.2       cli_3.6.1         knitr_1.43        rlang_1.1.1      
#>  [5] xfun_0.39         processx_3.8.1    purrr_1.0.1       styler_1.10.1    
#>  [9] promises_1.2.0.1  jsonlite_1.8.7    glue_1.6.2        htmltools_0.5.5  
#> [13] ps_1.7.5          chromote_0.1.1    rmarkdown_2.23    R.cache_0.16.0   
#> [17] evaluate_0.21     ellipsis_0.3.2    fastmap_1.1.1     yaml_2.3.7       
#> [21] lifecycle_1.0.3   compiler_4.3.0    fs_1.6.2          websocket_1.4.1  
#> [25] Rcpp_1.0.10       htmlwidgets_1.6.2 later_1.3.1       rstudioapi_0.14  
#> [29] R.oo_1.25.0       webshot2_0.1.0    R.utils_2.12.2    digest_0.6.31    
#> [33] R6_2.5.1          reprex_2.0.2      magrittr_2.0.3    webshot_0.5.4    
#> [37] R.methodsS3_1.8.2 tools_4.3.0       withr_2.5.0       d3r_1.0.1

Created on 2023-08-02 with reprex v2.0.2

kenneditodd commented 11 months ago

@SchmidtPaul Thank's for this code! It worked perfectly. I needed to specify the package (sankeyD3::sankeyNetwork) since I had networkD3 loaded too. Excited to see the improvements you will make with sankeyD3plus.