coloring edges in IGRAPH

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

coloring edges in IGRAPH

Bogdan Tanasa
Dear all,

I would appreciate a piece of advice please : I am aiming to color the
edges in a graph, by using IGRAPH package.

It works well for the big braph, however, when I decompose the graph into 2
subgraphs and color code those, the color of the edges change
(unexpectedly).

more precisely, as an example -- we have a dataframe :

el <- data.frame(Partner1=c(1, 3, 4, 5, 6), Partner2=c(2, 2, 5, 7, 7),
TYPE=c("DEL", "DEL", "DUP", "TRA", "TRA"))

el$COLOR[el$TYPE=="DEL"] <- "red"

el$COLOR[el$TYPE=="DUP"] <- "green"

el$COLOR[el$TYPE=="INS"] <- "yellow"

el$COLOR[el$TYPE=="INV"] <- "brown"

el$COLOR[el$TYPE=="TRA"] <- "blue"

#> el
#  Partner1 Partner2 TYPE COLOR
#1        1        2  DEL   red
#2        3        2  DEL   red
#3        4        5  DUP green
#4        5        7  TRA  blue
#5        6        7  TRA  blue

g <- graph_from_data_frame(d = el, directed = TRUE)

plot(g, edge.color=el$COLOR)

### here decomposing the graph into 2 SUBGRAPHS :

g_decompose <- decompose.graph(g)

plot(g_decompose[[1]], edge.color=el$COLOR) ## here the edges are red (that
is fine)

plot(g_decompose[[2]], edge.color=el$COLOR) ## here the edges shall be blue
and green, not red and green .

#####################################################

many thanks !

-- bogdan

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: coloring edges in IGRAPH

Bogdan Tanasa
Thank you all. Think I did solve it by using the code below :

plot(g_decompose[[1]], edge.color=edge_attr(g_decompose[[1]])$COLOR)

plot(g_decompose[[2]], edge.color=edge_attr(g_decompose[[2]])$COLOR)

On Tue, Jul 24, 2018 at 5:48 PM, Bogdan Tanasa <[hidden email]> wrote:

> Dear all,
>
> I would appreciate a piece of advice please : I am aiming to color the
> edges in a graph, by using IGRAPH package.
>
> It works well for the big braph, however, when I decompose the graph into
> 2 subgraphs and color code those, the color of the edges change
> (unexpectedly).
>
> more precisely, as an example -- we have a dataframe :
>
> el <- data.frame(Partner1=c(1, 3, 4, 5, 6), Partner2=c(2, 2, 5, 7, 7),
> TYPE=c("DEL", "DEL", "DUP", "TRA", "TRA"))
>
> el$COLOR[el$TYPE=="DEL"] <- "red"
>
> el$COLOR[el$TYPE=="DUP"] <- "green"
>
> el$COLOR[el$TYPE=="INS"] <- "yellow"
>
> el$COLOR[el$TYPE=="INV"] <- "brown"
>
> el$COLOR[el$TYPE=="TRA"] <- "blue"
>
> #> el
> #  Partner1 Partner2 TYPE COLOR
> #1        1        2  DEL   red
> #2        3        2  DEL   red
> #3        4        5  DUP green
> #4        5        7  TRA  blue
> #5        6        7  TRA  blue
>
> g <- graph_from_data_frame(d = el, directed = TRUE)
>
> plot(g, edge.color=el$COLOR)
>
> ### here decomposing the graph into 2 SUBGRAPHS :
>
> g_decompose <- decompose.graph(g)
>
> plot(g_decompose[[1]], edge.color=el$COLOR) ## here the edges are red
> (that is fine)
>
> plot(g_decompose[[2]], edge.color=el$COLOR) ## here the edges shall be
> blue and green, not red and green .
>
> #####################################################
>
> many thanks !
>
> -- bogdan
>
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.