0
votes

I will appreciate any help I can get. It says we have to read in the attached file and use it as an edge list to create a directed graph with weighted edges.

Then there are about 20 other things I have to do from there. This is part of the .txt file to import:

Columns are inbound locations, outbound locations, and travel time in minutes.

Inbound  Outbound  Minutes
ACY ATL 102
ACY FLL 136
ACY MCO 122
ACY MYR 90
ACY RSW 137
ACY TPA 129
ATL ACY 102
ATL BOS 132
ATL BWI 106
ATL CLE 104

.... and so on, there are probably 50+ locations in total, with around 400 lines

I tried using

read.graph(file.choose(), format="edgelist")

and when I select the .txt file I get the error:

"Error in read.graph.edgelist(file, ...) : 
  At foreign.c:101 : parsing edgelist file failed, Parse error"

-----EDIT----- I just used the following code:

inbound <- c(data[, 1])
outbound <- c(data[, 2])
testing <- data.frame(inbound, outbound)
gd <- graph_from_data_frame(testing, directed=TRUE,vertices=NULL)

Which gave this output:

edges from d654854 (vertex names):
  [1] 1 ->2  1 ->18 1 ->30 1 ->35 1 ->46 1 ->58 2 ->1  2 ->7  2 ->9  2 ->11 2 ->15 2 ->16 2 ->18 2 ->21 2 ->23 2 ->24 2 ->30
 [18] 2 ->33 2 ->34 2 ->36 2 ->37 2 ->41 2 ->58 3 ->18 4 ->18 5 ->18 5 ->30 5 ->35 5 ->46 5 ->58 6 ->18 7 ->2  7 ->9  7 ->11
 [35] 7 ->15 7 ->16 7 ->18 7 ->23 7 ->30 7 ->33 7 ->34 7 ->35 7 ->37 7 ->58 8 ->18 9 ->2  9 ->7  9 ->13 9 ->15 9 ->16 9 ->18
 [52] 9 ->21 9 ->23 9 ->24 9 ->30 9 ->33 9 ->34 9 ->35 9 ->36 9 ->37 9 ->48 9 ->51 9 ->58 10->18 10->23 10->30 10->35 11->2 
 [69] 11->7  11->15 11->18 11->23 11->24 11->30 11->34 11->35 11->51 12->18 13->9  13->15 13->18 13->21 13->37 14->15 14->16
 [86] 14->18 14->21 14->23 14->24 14->26 14->30 14->33 14->37 15->2  15->7  15->9  15->11 15->13 15->14 15->16 15->18 15->23
[103] 15->24 15->26 15->30 15->33 15->34 15->35 15->36 15->37 15->41 15->42 15->43 15->48 15->52 15->58 16->2  16->7  16->9 
[120] 16->14 16->15 16->18 16->21 16->23 16->24 16->26 16->29 16->30 16->33 16->34 16->35 16->36 16->41 16->46 16->54 16->58
+ ... omitted several edges

Is that what I am supposed to get? Or am I still way off?

Using is.igraph(gd) returns true, and using V(gd) and E(gd) both return information.


So I guess my question is how do I properly import the "table" so that the pairs of inbound/outbound flight names are used as edges (I think) for this? I have to make a directed graph with weighted edges to finalize the set up.

Any information on where I should start? I looked through the igraph documentation but I can't find anything about importing from a table and using pairs of characters as edges.

1
Is the image not visible to you? I attached some data just in case! Sorry about that.a8d9add11bff124c0fbddd7a6607
My location blocks most images. I did not see it. Thanks for adding the data.G5W

1 Answers

2
votes

You can import the data as a data.frame and coerce it to a graph. Once you have the graph, you can assign weights.

library(igraph)

xy <- read.table(text = "
ACY ATL 102
ACY FLL 136
ACY MCO 122
ACY MYR 90
ACY RSW 137
ACY TPA 129
ATL ACY 102
ATL BOS 132
ATL BWI 106
ATL CLE 104", header = FALSE, sep = " ")
colnames(xy) <- c("node1", "node2", "weight")

g <- graph_from_data_frame(xy[, c("node1", "node2")])
E(g)$weight <- xy$weight

plot(g, edge.width = E(g)$weight/50, edge.arrow.size = 0.1)