9

I have a network that, when I plot it, has a number of overlapping nodes. I want to change the opacity of the colors so that you can see nodes underneath others when they overlap. As an example, see this video: https://vimeo.com/52390053

I'm using iGraph for my plots. Here's a simplified blurb of code:

net1 <- graph.data.frame(myedgelist, vertices=nodeslist, directed = TRUE)

g <- graph.adjacency(get.adjacency(net1))

V(g)$color <- nodeslist$colors  #This is a set of specific colors corresponding to each node. They are in the format "skyblue3". (These plot correctly for me). 

E(g)$color <-"gray" 

plot.igraph(g)

I can't, however, find an option in iGraph to change the opacity of the node colors.

Any idea how I might do this? I thought maybe something like V(g)$alpha <- 0.8, but this doesn't do anything.

parakmiakos
  • 2,994
  • 9
  • 29
  • 43
Net20
  • 105
  • 1
  • 5

2 Answers2

11

You might wanna try e.g. this:

library(igraph)
set.seed(1)
g <- barabasi.game(200)
plot(g, 
     vertex.color = adjustcolor("SkyBlue2", alpha.f = .5), 
     vertex.label.color = adjustcolor("black", .5))

enter image description here

lukeA
  • 53,097
  • 5
  • 97
  • 100
  • 1
    Perfect, thanks. I adjusted it into my code as follows: plot(g, vertex.color = adjustcolor(nodeslist$colors, alpha.f = .5)) Interestingly, it doesn't work with tkplot(), only plot(). As I need to move some things around, I'll need to incorporate the tkplot() coordinates into the normal plot() function and then do the opacity changes there. – Net20 May 21 '15 at 15:14
8

A way I find easier to control than the method provided by lukeA is to use rgb(). You can specify color (of a node, node frame, edge, etc.) in terms of its four channels: R, G, B, and A (alpha):

library(igraph)
set.seed(1)
g <- barabasi.game(200)
plot(g, 
     vertex.color = rgb(0,0,1,.5), 
     vertex.label.color = rgb(0,0,0,.5))

enter image description here

Another advantage is you can easily vary alpha (or color) according to a vector. The example below isn't exactly practical, but you get the idea how this could be used:

library(igraph)
set.seed(1)
g <- barabasi.game(200)

col.vec <- runif(200,0,1)
alpha.vec <- runif(200,0,1)

plot(g, 
     vertex.color = rgb(0,0,col.vec,alpha.vec), 
     vertex.label.color = rgb(0,0,0,.5))

enter image description here

Dan
  • 113
  • 1
  • 5