Creating graph from a matrix.

87 Views Asked by At

I have an n.n matrix, like the following picture and I want to create a graph that shows me the relationship between them.

enter image description here

In this case that is a real case, I have 4 column that contains traffic flow of a computer network, and the elements ere [Source IPs, Source Ports, Destination IPs, Destination Ports], As I did a little bit of search about this issue, I can use R studio and "ggplot" function. I have two questions and I would appreciate you in advance if you can help me to do this job or at least give me more hint or clue to do it.
The first question is how to create a graph from a matrix?
The second question is how can I do I practically like using software like RStudio?

1

There are 1 best solutions below

0
On BEST ANSWER

Check out the Graphviz graph layout and visualization package

Using your example data, the directed graph can be described as ip.dot file:

digraph{
  splines=true;
  rankdir=LR;
  "X.X.1.2:46564" -> "192.168.12.12:8080"
  "X.X.1.3:46547" -> "192.168.20.20:443"
  "X.X.1.4:32131" -> "192.168.15.2:80"
  "X.X.1.2:12456" -> "192.168.15.2:80"
  "X.X.1.5:65231" -> "192.168.20.20:443"
  "X.X.1.2:52461" -> "192.168.42.13:6513"
  "X.X.1.5:48532" -> "192.168.15.2:80"
  "X.X.1.5:15246" -> "192.168.20.20:443"
  "X.X.1.4:16542" -> "192.168.1.12:135"
  "X.X.1.4:68452" -> "192.168.15.2:80"
  "X.X.1.2:46813" -> "192.168.1.12:135"
  "X.X.1.2:16895" -> "192.168.20.20:443"
  "X.X.1.7:36555" -> "192.168.15.2:80"
}

and the dot -Tps ip.dot command generates a graph

enter image description here