3
votes

I am trying to use igraph/ggraph to plot a network, in which some of the edges are directed and others are not.

A small example from my edgelist. Here the protein-site edges are what I want to represent as undirected and the phosphorylation edge as directed.

df <- data.frame(
  stringsAsFactors = FALSE,
              from = c("RPS6KA3", "RPS6KA3", "RPS6KA3", "RPS6KA3", "RPS6KA3"),
                to = c("RPS6KA3_Y529-p",
                       "RPS6KA3_S227-p","RPS6KA3_S369-p","RPS6KA3_T577-p","ATF4"),
            action = c("protein-site","protein-site",
                       "protein-site","protein-site","phosphorylation")
)

I have tried subsetting the undirected edges and specifying them as such, but it didn't work:

library(igraph)
nw <- graph_from_data_frame(df)

E(nw)[E(nw)$action == "protein-site"] <- as.undirected(subgraph.edges(nw, E(nw)[E(nw)$action == "protein-site"] ))

Does anyone have any other suggestions? As I say, I am really only wanting to plot this (using ggraph).

Thanks!

1
Is this simply a visualization question? Or are you trying to do something with such a graph?Szabolcs

1 Answers

3
votes

If you would be willing to plot with igraph you can import the list of edges as directed and then use edge.arrow.mode.

nw <- graph_from_data_frame(df, directed = T)


plot(nw)

enter image description here

plot(nw,
     edge.arrow.mode = ifelse(E(nw)$action=="protein-site", "-", ">"))

enter image description here

I am not sure ggraph supports anything similar. I thought it might be possible to change the size of the arrows, and set it to 0 for undirected edges. This doesnt work, as arrows inherit the style of the rest of the edge.