Rafa Mesa
Rafa Mesa

Reputation: 75

How to convert igraph file in row/colums?

I would like to pass the information I have to a normal list of axes with nodes but I don't know how to do it. The raw data with "deput" would look like this. If someone knows how to convert this list into something easier to use I would appreciate it.I can visualise the graph with "plot" but to edit it I need to have more precise information.

library(igraph)
dput (net2$graph_pajek)
structure(list(30, FALSE, c(1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 
3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 6, 7, 13, 13, 
14, 15, 16, 18, 20, 20, 21, 27, 27, 27, 27, 29, 2, 2, 2, 2, 2, 
2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 
6, 6, 7, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10, 11, 11, 12, 12, 12, 
13, 13, 13, 14, 14, 14, 15, 15, 15, 16, 18, 18, 18, 19, 20, 20, 
21, 21, 23, 24, 25, 26, 27, 27, 27, 29, 3, 3, 3, 3, 3, 3, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 
5, 5, 5, 5, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 10, 
10, 10, 10, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
12, 12, 12, 12, 12, 12, 13, 13, 14, 14, 15, 15, 15, 15, 15), list(c(1, 0, 1), structure(list(), .Names = character(0)), 
    list(name = c("A", "B", "C", 
    "D", "E", "F", "G", "H", 
    "I", "J", "K", 
    "L", "M", "N", 
    "O", "P", "Q", "R", 
    "S", "T", "U", 
    "V", "W", "X", "Y", "Z", 
    "AB", "AC", "AD", "AE"
    ), deg = c(248, 532, 855, 574, 1761, 261, 229, 216, 554, 
    628, 774, 223, 502, 295, 266, 910, 227, 312, 364, 260, 294, 
    741, 227, 471, 392, 376, 292, 295, 212, 287), size = c(2., 
    6, 9, 6, 20, 
    2, 2, 2, 6, 
    7, 8, 2, 7, 
    3, 3, 10, 2, 
    3, 4, 2, 3., 
    8, 2, 5, 4, 
    4, 3, 3, 2, 
    3), label.cex = c(0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 
    0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 
    0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7
    ), id = c("A", "B", "C", 
    "D", "E", "F", "G", "H", 
    "I", "J", "K", 
    "L", "M", "N", 
    "O", "P", "Q", "R", 
    "S", "T", "U", 
    "V", "W", "X", "Y", "Z", 
    "AB", "AC", "AD", "AE"
    )), list(num = c(4, 4, 4, 4, 7, 7, 7, 7, 7, 7, 7, 3, 3, 3, 
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 3, 3, 3, 1, 1, 2, 
    2, 1, 1, 1, 1, 2, 2, 1, 4, 4, 4, 4, 1, 7, 7, 7, 7, 7, 7, 
    7, 6, 6, 6, 6, 6, 6, 12, 12, 12, 12, 12, 12, 12, 12, 12, 
    12, 12, 12, 1, 2, 2, 1, 2, 2, 3, 3, 3, 5, 5, 5, 5, 5, 2, 
    2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3, 1, 2, 
    2, 2, 2, 1, 1, 1, 1, 3, 3, 3, 1, 6, 6, 6, 6, 6, 6, 40, 40, 
    40, 40, 40, 40, 40, 40, 40), weight = c(4, 4, 4, 4, 
    7, 7, 7, 7, 7, 7, 7, 3, 3, 3, 10, 10, 10, 10, 10, 10, 10, 
    10, 10, 10, 3, 3, 3, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 1, 4, 
    4, 4, 4, 1, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 12, 12, 
    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 1, 2, 2, 1, 2, 2, 
    3, 3, 3, 5, 5, 5, 5, 5, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 
    3, 3, 3, 1, 3, 3, 3, 1, 2, 2, 2, 2, 1, 1, 1, 1, 3, 3, 3, 
    1, 6, 6, 6, 6, 6, 6, 40, 40, 40, 40, 40, 40, 40, 40, 40, 
    40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 
    40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 
    40, 7, 7, 7, 7, 7, 7, 7, 1, 3, 3, 3, 7, 7, 7, 7, 7, 7, 7, 
    4, 4, 4, 4, 4, 4, 4, 4, 1, 18, 18))), <environment>), class = "igraph")

Upvotes: 0

Views: 55

Answers (2)

ThomasIsCoding
ThomasIsCoding

Reputation: 101247

Are you looking for something like get.data.frame

> get.data.frame(net)
   from to     weight
1     A  B 0.63502922
2     B  C 0.79410173
3     C  D 0.90802625
4     D  E 0.09408188
5     E  F 0.16450634
6     F  G 0.75931882
7     G  H 0.30409658
8     H  I 0.23990324
9     I  J 0.84762277
10    A  J 0.88657718

data

Since I cannot reproduce the example in your post, I created a dummy example net like below

net <- make_ring(10) %>%
  set_vertex_attr(name = "name", value = LETTERS[1:vcount(.)]) %>%
  set_edge_attr(name = "weight", value = runif(ecount(.)))

Upvotes: 1

anymous.asker
anymous.asker

Reputation: 1259

To clarify a couple things:

  • The igraph file is not a plot per se, but a graph structure (as in, nodes and edges).
  • igraph has functions for plotting graphs, but there is no single and standard way of plotting a graph - instead, different algorithms can be used to determine visually-ideal ways of displaying them, and these algorithms oftentimes rely on random initializations.
  • The outputs from the plotting functions of igraph are only relevant in terms of R base plot drawing logic, AFAIK they don't use an intermediate format with coordinates handled in a user-comprehensible structure. You can nevertheless manage lots of aspects of how they are drawn - see ?igraph::igraph.plotting.

Upvotes: 0

Related Questions