datastorm-open / visNetwork

R package, using vis.js library for network visualization
Other
545 stars 125 forks source link

why the color in network shows different with my settings #447

Open chenc327 opened 2 years ago

chenc327 commented 2 years ago

Hi, thanks for this outstanding tools.I'm just a beginner in this software I WANT to know why the color in network shows different with my settings in node. I have setted the color to be orange and grey, but finally got a plot in different color. THANKS

node <- data.frame(id = unique(c(edge$from,edge$to)),
                   label = c(unique(edge$from),rep(NA,308)),
                   group = c(rep('Regulon',12),rep('target',308)),
                   value = (as.numeric(c(rep(4,12),table(edge$to))))*5,
                   shape = c(rep('square',12),rep('circle',308)),
                   color = c(rep('orange',12),rep('grey',308))
                   )
visNetwork(node, edge, width = 500, height = 500, main = "prog network")

image

bthieurmel commented 2 years ago

If you are using groups, you have to defined groups options using visGroups

?visGroups

nodes <- data.frame(id = 1:10, label = paste("Label", 1:10), 
 group = sample(c("A", "B"), 10, replace = TRUE))
 edges <- data.frame(from = c(2,5,10), to = c(1,2,10))

visNetwork(nodes, edges) %>%
 visLegend() %>%
 visGroups(groupname = "A", color = "red", shape = "database") %>%
 visGroups(groupname = "B", color = "yellow", shape = "triangle")