0

I am using R to plot network graph. The matrix of interactions looks

>mat
    9   401 562 68  71  569 700
9   0   1   0   0   0   0    1
401 0   0   1   0   0   na   1
562 0   1   0   1   1   0    1 
68  1   1   0   0   0   0    1
71  1   na  0   0   na  0    1
569 1   1   0   1   0   0    0
700 0   0   0    0   0  0    0

>DT_mat<-mat%>%
 as.data.table(keep.rownames=TRUE) %>% 
 melt(id.vars = "rn", value.name="interaction")
>setnames(DT_mat, c("rn", "variable"),  c("source", "target"))

The metadata for Ids of the same matrix of interactions

    >meta
compart group family  genus color.group  color.compart
9    Ex     Prt   A       Ps #EF5656      #2BB065
401  Ex     Prt   A       Ps #EF5656      #2BB065  
562  Ex     Fir   B       Rh #F7A415      #2BB065 
68   In     Fir   C       En #F7A415      #EECF17
71   In     Act   D       Stp #47B3DA     #EECF17  
569  In     Act   D       Stp #47B3DA     #EECF17
700  Ex     Act   E       Aqua #47B3DA    #2BB065

>DT_meta <- as.data.table(meta, keep.rownames=TRUE)
>setkey(DT_meta, rn)
>DT_mat[, paste0(names(DT_meta), ".rows") :=  DT_meta[.(rn.rows)]]

1-Is it possible to define colors using qgraph()?

> ig_mat <- graph.data.frame(DT_mat, directed=T)
> V(mat)$color <- ifelse(V(mat)$compart=="Ex","#EF5656","#47B3DA")

2-Is it possible to define colors using igraph.plot when there are more than two colors and ovoid using efelse in repetition?

  • You want to define your colors based on the values of the column *compart*? – ddiez May 22 '15 at 07:03
  • I only have answer to point 2) above: you can use the `recode` function from the `car` package (see http://www.inside-r.org/packages/cran/car/docs/recode ) – Tamás May 22 '15 at 08:28
  • Thank you. I found part of the answer in qgraph tutorial. I define a matrix with colors code as content. I call the matrix when plotting the graph. colors=my_matrix_color – user3037937 Jun 15 '15 at 21:08

0 Answers0