Browse code

fixing graph backbone function where NAs are around

Federico Marini authored on 07/10/2022 12:25:19
Showing 1 changed files

... ...
@@ -437,9 +437,16 @@ ggs_backbone <- function(res_enrich,
437 437
           colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 1
438 438
         ))
439 439
 
440
-        V(bbgraph)$color.background <- map2color(col_var, mypal, limits = range(col_var))
441
-        V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, limits = range(col_var))
442
-        V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, limits = range(col_var))
440
+        V(bbgraph)$color.background <- map2color(col_var, mypal, symmetric = TRUE,
441
+                                                 limits = range(na.omit(col_var)))
442
+        V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, symmetric = TRUE,
443
+                                                limits = range(na.omit(col_var)))
444
+        V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, symmetric = TRUE,
445
+                                            limits = range(na.omit(col_var)))
446
+        
447
+        V(bbgraph)$color.background[is.na(V(bbgraph)$color.background)] <- "lightgrey"
448
+        V(bbgraph)$color.highlight[is.na(V(bbgraph)$color.highlight)] <- "lightgrey"
449
+        V(bbgraph)$color.hover[is.na(V(bbgraph)$color.hover)] <- "lightgrey"
443 450
 
444 451
         V(bbgraph)$color.border <- "black"
445 452
 
... ...
@@ -461,10 +468,17 @@ ggs_backbone <- function(res_enrich,
461 468
           colorRampPalette(RColorBrewer::brewer.pal(name = "RdYlBu", 11))(50), 1
462 469
         ))
463 470
 
464
-        V(bbgraph)$color.background <- map2color(col_var, mypal, limits = range(col_var))
465
-        V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, limits = range(col_var))
466
-        V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, limits = range(col_var))
467
-
471
+        V(bbgraph)$color.background <- map2color(col_var, mypal, 
472
+                                                 limits = range(na.omit(col_var)))
473
+        V(bbgraph)$color.highlight <- map2color(col_var, mypal_select, 
474
+                                                limits = range(na.omit(col_var)))
475
+        V(bbgraph)$color.hover <- map2color(col_var, mypal_hover, 
476
+                                            limits = range(na.omit(col_var)))
477
+
478
+        V(bbgraph)$color.background[is.na(V(bbgraph)$color.background)] <- "lightgrey"
479
+        V(bbgraph)$color.highlight[is.na(V(bbgraph)$color.highlight)] <- "lightgrey"
480
+        V(bbgraph)$color.hover[is.na(V(bbgraph)$color.hover)] <- "lightgrey"
481
+        
468 482
         V(bbgraph)$color.border <- "black"
469 483
 
470 484
         # additional specification of edge colors