SWR
SWR

Reputation: 505

igraph does not show the right network I imported

I would like run some sna analysis. I work with RStudio and the igraph Package. My input data is from a text file (created from excel as a tab seperated text file). The data file has 3 columns. 1st and 2nd row are network data (vertices) and the 3rd row is the weight for each edge. I use airport connections data that looks like this:

1 54 28382 (Airport ID Origin Airport / Airport ID Destination Airport / Passanger number as a weight)

I loaded id with these commands:

 USAN_num1 <- read.table('USAN_num.txt', header=T)
 USAN_g_num1 <- graph.data.frame(USAN_num1)
> summary(USAN_g_num1)
Vertices: 626 
Edges: 7078 
Directed: TRUE 
No graph attributes.
Vertex attributes: name.
Edge attributes: PAX.

Data looks like this:

  ORIGN DESTN  PAX
1     1   604  646
2     2    42 3736
3     2   118 5189

Now to the problem that occured: My network consints of 6 different clusters when I check it with igraph. Even when I create a graphical picture of my network it has 6 seperated parts. That makes totally no sense since my data should be connected to one network. I checked through my dataset and there really are not different sub-networks.

Here is the cluster characteristics I get:

$csize
[1]   5 608   2   4   5   2

$no
[1] 6

One vertice in a small cluster is even a huge airport that should be connected to many others and not just 1 other...

UPDATE: I now updated to the newest igraph version but it still does not work. I uploaded an exemplary part of my data as a .txt file here: USAN_numS.txt

Would be great if someone has an idea on what I did wrong. Thank you

Upvotes: 0

Views: 546

Answers (1)

Gabor Csardi
Gabor Csardi

Reputation: 10825

So, as I said above the in my comment, a possible source of confusion is that your graph has symbolic vertex names that are actually numbers and don't match igraph's vertex ids. The workaround is to drop the vertex names, or to specify them explicitly when creating the graph, so that they match the igraph vertex ids.

But your graph really has multiple components, see the following code, where I check it in the original table, that two vertices only appear exactly once in the table, and they form a component of two by themselves.

Maybe the network really has multiple components, or there are mistakes in the file.

library(igraph)
USAN_num1 <- read.table('USAN_numS.txt', header=T)
USAN_g_num1 <- graph.data.frame(USAN_num1,
                   vertices=data.frame(id=1:max(USAN_num1[,1:2])))    
clu <- clusters(USAN_g_num1)
clu$csize
## [1]   5 607   2   4   5   1   2   1
## The '1's appear because we counted the vertices that are 
## not in the table

## Third component has two vertices only, let's check them in the
## original table
which(clu$membership == 3)
## [1]  64 617

## List the table rows where any of these two appear
USAN_num1[ USAN_num1[,1] %in% c(64, 617) | USAN_num1[,1] %in% c(64, 617), ]
##     ORIGN DESTN PAX
## 691    64   617 636

Upvotes: 1

Related Questions