-1

I have a square matrix in which each elements contains the amount of connexions between the points associated with the corresponding row and column. I also have a list of coordinates for each of those points. My purpose is to plot this matrix such that the points are represented according to their coordinates and that the number of connections beween them are represented by lines of different thickness. I've tried using the igraph package to do this but I can't find a way to associate geographical coordinates to my rows and columns.

My current code is the following:

    library(igraph)
    connectivityMatrix <- as.matrix(read.table(file='settlementMatrix004800.dat'))
    g <- graph.adjacency( connectivityMatrix, weighted=TRUE, mode="undirected" )
    plot(g)

This plots the points and the connections but the topology of the network is not taken into account. I also tried with the statnet package and couldn't either find a way to take into account the coordinates.

    library(statnet)
    connectivityMatrix <- as.matrix(read.table(file='settlementMatrix004800.dat'))
    net <- as.network(connectivityMatrix, matrix.type = "adjacency", directed = TRUE)
    bet <- betweenness(net)
    gplot(net, mode="segeo")

Do you have a good advice to do this?

Thanking you in advance,

user3584444
  • 457
  • 1
  • 7
  • 12
  • If you have a specific coding question, I suggest you phrase it that way. As the question stands, it's seeking someone to do consultant work, for which stackoverflow is not well suited. – Roman Luštrik Jan 06 '15 at 12:23
  • This isn't clear on various levels. An adjacency matrix doesn't contain "a number of connections", it should be binary: 0=not adjacent, 1=adjacent. What does "474 spatial locations two by two" mean? For a line between point A and B you want the linewidth to be proportional to what? Is your adjacency matrix really not an adjacency matrix? Show example data, and anything you've tried. – Spacedman Jan 06 '15 at 12:35

1 Answers1

0

The idea is to get a list of non-zero entries in the adjacency matrix, find out their entry index (via row and col), find the corresponding coordinates, and then use the segments function to join them up. Here's an example of a maximally connected three-vertex graph:

adj <- matrix(1, 3,3)
x <- 1:3
y <- c(1,2,1)
plot(x,y)
isLine <- which(adj!=0)
segments(x[row(adj)[isLine]], y[row(adj)[isLine]], x[col(adj)[isLine]], y[col(adj)[isLine]],   lwd=adj[isLine])
Gavin Kelly
  • 2,374
  • 1
  • 10
  • 13