The color palette for the vertices in the igraph network in R

I draw a network graph in R using `igraph1. The network has 1380 nodes and about 150 Kb. Here is a summary from igraph:

IGRAPH UN-- 1380 159718 -- 
+ attr: name (v/c), rels (v/n), label (v/n), degree (v/n), btw (v/n), color (v/c), rels (e/n)

I am trying to add a color gradient that colors nodes based on their centrality. I tried a couple of different versions of the code, first from this:

# calculate betweenness
V(g_yearly)$btw <- betweenness(g_yearly)

# construct color palette
fine <- 100
palette <- colorRampPalette(c('blue','green'))

# assign palette to nodes
V(g_yearly)$color <- palette(fine) [as.numeric(cut(V(g_yearly)$btw,breaks=fine))]

# plot network 
plot.igraph(g_yearly,vertex.shape="circle",vertex.size=1,vertex.label.cex=0.6,layout=lgl(g_yearly),edge.arrow.size=0,edge.width=E(g_yearly)$rels/50)

I get the following error and trace:

Error in seq.int(0, 1, length.out = n) : 
  'length.out' must be a non-negative number 
  9 .approxfun(x, y, v, method, yleft, yright, f) 
  8 palette[[1L]](x) 
  7 cbind(palette[[1L]](x), palette[[2L]](x), palette[[3L]](x), if (alpha) palette[[4L]](x)) 
  6 pmin(rgb, 1) 
  5 pmax(pmin(rgb, 1), 0) 
  4 roundcolor(cbind(palette[[1L]](x), palette[[2L]](x), palette[[3L]](x), 
if (alpha) palette[[4L]](x))) 
  3 ramp(seq.int(0, 1, length.out = n)) 
  2 palette(palette) 
  1 plot.igraph(g_yearly, vertex.shape = "circle", vertex.size = 1, 
vertex.label.cex = 0.6, layout = layout.lgl(g_yearly), edge.arrow.size = 0, 
edge.width = E(g_yearly)$rels/50) 

In addition: Warning message:
In .approxfun(x, y, v, method, yleft, yright, f) :
NAs introduced by coercion

If I use the function rainbowinstead, this works just fine:

V(g_yearly)$color <- rainbow(V(g_yearly)$btw,start=3/6,end=4/6)

Oddly enough, after I once launched the first bit of code, I cannot start a conspiracy on the network without getting the same error - even if I delete the calls on palette.

What am I doing wrong with palette?

+3
source share
3 answers

, :

# assign palette to nodes
V(g_yearly)$color <- palette(fine [as.numeric(cut(V(g_yearly)$btw,breaks=fine))]

palette , fine - 1, -, 1, . :

V(g_yearly)$color <- palette(fine)[ as.numeric( cut(V(g_yearly)$btw, breaks=fine)]   

( .)

+1

, .

palette <- colorRampPalette(c('blue','green'))

"", igraph ( , igraph "" .

, ,

palette <- colorRampPalette(c('blue','green'))

.

+1

: 2 (). , , : < - colorRampPalette (c ('', ''))

-1

All Articles