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.
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))
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))
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With