R reciprocal edges in igraph in R

前端 未结 2 825
名媛妹妹
名媛妹妹 2020-12-21 01:38

I am working with graphs in R. I am currently using igraph and I would like to be able to plot bidirectional edges \"reciprocal edges\" of a graph. So far I\'ve seen it is p

相关标签:
2条回答
  • 2020-12-21 02:21

    In igraph, you can use the edge attribute curved to curve the edges you want.

    For example, here is a graph based small adjacency matrix:

    library("igraph")
    adj <- matrix(c(
        0,1,1,
        1,0,1,
        0,0,0),3,3,byrow=TRUE)
    
    library("igraph")
    G <- graph.adjacency(adj)
    

    The edge between node 0 and 1 is bidirected (Actually, it isn't, it are two edges and they just look like a bidirected edge because they are straight).:

    plot(G)
    

    To change this, we can use the edgelist:

    E <- t(apply(get.edgelist(G),1,sort))
    
    E(G)$curved <- 0
    E(G)[duplicated(E) | duplicated(E,fromLast =TRUE)]$curved <- 0.2
    
    plot(G)
    

    Another option is my package, where this is the default behavior:

    library("qgraph")
    qgraph(adj)
    

    which can be suppressed with the bidirectional argument.

    0 讨论(0)
  • 2020-12-21 02:22

    Try plot(graph, edge.curved=TRUE). It definitely works in igraph 0.6, and it may also work in igraph 0.5.4 (not sure when it was added).

    0 讨论(0)
提交回复
热议问题