根据属性着色的igraph边缘消失

时间:2018-12-06 19:50:58

标签: r colors network-programming igraph

我想根据另一个边缘属性在igraph中为网络的边缘着色。

这是我所做的:

void SubtractFloat (void *in, void *out){

    int* a = (int*)in;
    int* b = a++;

    float c = * (float*)a;
    float d = * (float*)b;

    float* e = (float*)out;

    *e = c - d;
}

这里出现错误,或者根本没有边缘。

vector <- c("a","b","b","d","b","c","c","a")
field <- c("friend","friend","good friend","archenemy")

g <- graph(vector, directed = FALSE)
E(g)$status <- field

library(RColorBrewer)
color = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = 
T)]
n <- length(unique(field))

col=sample(color, n)
sec=unique(field)
coloring <- as.list(setNames(col,sec))

E(g)$color <- coloring[E(g)$status]

1 个答案:

答案 0 :(得分:0)

这对我有用。您的原始代码列出了g中的颜色。选中E(g)$color

library(igraph)
library(RColorBrewer)
color = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]

vector <- c("a","b","b","d","b","c","c","a")
field <- c("friend","friend","good friend","archenemy")
####
g <- graph(vector, directed = FALSE)
E(g)$status <- field

n <- length(unique(field))
col=sample(color, n)

coloring <- col[factor(field)]
E(g)$color <- coloring

plot(g)