title: How to create a legend for edge colors when plotting networks in R?
body: <p>I have generated a connectivity matrix representing a network of geographical points connected by ocean currents. Each point releases particles that are received by the others. The number of particles released and received by each point is summarized in this square matrix. For example an element Aij of the matrix correspond to the amount of particles emitted by the ith point and received by the jth.</p>
  
  <p>My purpose is to be able to plot this as a network such that each point constitutes a vertex and the connections between two points constitute an edge. I would like those edges to be of different colors according to the amount of particles exchanged. Those have to be marked by an arrow. </p>
  
  <p>I could plot those points according to their geographic coordinates and I could plot those edges the way I wanted. My only concern is now how to add a legend relating the color of the edges with the amount of particles they represent.</p>
  
  <p>Can anyone help me with that? Here is my code so far:</p>
  
  <pre><code>library(ggplot2)
  library(plyr)
  library(sp)
  library(statnet)
  
  connectivityMatrix &lt;- as.matrix(read.table(file='settlementMatrix001920.dat'))
  coordinates &lt;- as.matrix(read.table(file='NoTakeReefs_center_LonLat.dat'))
  
  
  net &lt;- as.network(connectivityMatrix, matrix.type = "adjacency", directed =   TRUE)
  
  minX&lt;-min(coordinates[,1])#-0.5
  maxX&lt;-max(coordinates[,1])#+0.5
  minY&lt;-min(coordinates[,2])#-0.5
  maxY&lt;-max(coordinates[,2])#+0.5
  
  
  p&lt;-plot(net, coord=coordinates,xlim=c(minX,maxX),ylim=c(minY,maxY),edge.col=connectivityMatrix,object.scale=0.01)    
  </code></pre>