7

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.

4

2 回答 2

11

你可能想试试这个:

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

在此处输入图像描述

于 2015-05-21T14:48:09.827 回答
6

我发现比 lukeA 提供的方法更容易控制的一种方法是使用 rgb()。您可以根据其四个通道指定颜色(节点、节点框架、边缘等):R、G、B 和 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))

在此处输入图像描述

另一个优点是您可以根据向量轻松改变 alpha(或颜色)。下面的示例并不完全实用,但您知道如何使用它:

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))

在此处输入图像描述

于 2016-02-10T20:23:27.560 回答