briatte / ggnet

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

Legend Title #18

Closed Btibert3 closed 8 years ago

Btibert3 commented 8 years ago

I am probably missing something obvious, but is is possible to remove the legend title and just show the legend values when using the parameter color?

For context, I was thinking something along the lines of

ggnet2(g, 
       color = "ntype", 
       palette = col, 
       mode = "fruchtermanreingold", 
       alpha=.7, 
       legend.position = "bottom", 
       legend.title=element_blank())
briatte commented 8 years ago

Yes, that's possible if you 'externalize' the legend.title argument, since it has to go in theme to work:

library(GGally)
library(ggplot2)
library(network)

g = network(sna::rgraph(10))
g %v% "ntype" = sample(1:2, 10, replace = TRUE)
col = c("1" = "gold", "2" = "tomato")

ggnet2(g, 
       color = "ntype", 
       palette = col, 
       mode = "fruchtermanreingold", 
       alpha=.7, 
       legend.position = "bottom") +
  theme(legend.title=element_blank())

I would like to recommend that you try ggnetwork: its syntax is closer to that of ggplot2 than is the case for ggnet2. Take a look at the package vignette for examples.