briatte / ggnet

Network visualization with ggplot2
https://briatte.github.io/ggnet/
194 stars 33 forks source link

vertex color custom palette w/ 1 level #31

Closed prummer closed 5 years ago

prummer commented 7 years ago

When the vertex attribute V(net)$color has only 1 unique label (="Mixed"), then

ggnet2(net, color="color", palette="Set1")

works fine but

ggnet2(net, color="color", palette=custom_palette)

does not:

Error in grDevices::col2rgb(colour, TRUE) : invalid color name 'Mixed'

The workaround

ggnet2(net, color = custom_palette[V(net)$Direction])

does the trick but does not plot a legend.

This behavior is unexpected to me. Maybe you can provide help or a fix.

Thanks in advance & best regards

Michael.

briatte commented 5 years ago

Hi @prummer

Thanks for reporting this, and sorry for answering this so very, very late.

I'm failing to reproduce the issue:

# build graph
net <- sna::rgraph(10, mode = "graph", tprob = 0.5)
net <- network::network(net, directed = FALSE)

# single-color palette
net %v% "color" <- "foo"
custom_palette <- c("foo" = "red")

ggnet2(net, color = "color")        # all nodes are grey
ggnet2(net, color = custom_palette) # all nodes are red

Please post a reproducible example if you are still facing the issue.