本文介绍了igraph对象可以具有有向边和无向边吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用igraph/ggraph绘制网络,其中某些边是定向的,而其他边则不是.

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"] ))

还有其他建议吗?正如我所说的,我真的只想绘制此图(使用ggraph).

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

谢谢!

推荐答案

如果愿意使用igraph进行绘制,则可以按照指示导入边缘列表,然后使用edge.arrow.mode.

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)
plot(nw,
     edge.arrow.mode = ifelse(E(nw)$action=="protein-site", "-", ">"))

我不确定ggraph是否支持任何类似内容.我认为可能可以更改箭头的大小,并为无方向的边缘将其设置为0.这是行不通的,因为箭头继承了边缘其余部分的样式.

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.

这篇关于igraph对象可以具有有向边和无向边吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:44