For curved lines, you could use the bezier library.
In this example, I generate a bezier line with random curvature within a
specific range :
from = mst.bh[i, 1] # coordinates of the source node
to = mst.bh[i, 2] # coordinates of the target node
d = sqrt((coords[from, 1] - coords[to, 1])^2 + (coords[from, 2] -
coords[to, 2])^2) # the distance bewteen the two nodes
midpoint = c((coords[from, 1] + coords[to, 1])/2 + ifelse(runif(1,-1,1) >
0, 1, -1) * runif(1,0,d/3),
(coords[from, 2] + coords[to, 2])/2 +
ifelse(runif(1,-1,1) > 0, 1, -1) * runif(1,0,d/3))
b = bezier(t=t <- seq(0, 1, length=100), p=rbind(coords[from, ],
midpoint, coords[to, ]))
rowname = paste(from, to, sep="_")
l = makeLineFromCoords(b, rowname)
2016-02-25 11:44 GMT+01:00 Luca Candeloro <luca.candeloro at gmail.com>:
Thank you Mathieu,
in the way you propose, however, you get straight lines...
I'd like instead to have curved edges.
any suggestions?
cheers, luca
2016-02-25 11:39 GMT+01:00 Mathieu Rajerison <mathieu.rajerison at gmail.com
Hi,
Recently, I used igraph with spatial objects.
Once you have the coordinates of the nodes composing an edge, you can
transform it into a spatiallines object with this function :
makeLineFromCoords <- function(coords, i) {
Sl1 = Line(coords)
S1 = Lines(list(Sl1), ID=as.character(i))
Sl = SpatialLines(list(S1))
return(Sl)
}
For all the routing stuff within R, this resource by B. Rowlingson is
quite inspiring :
http://rstudio-pubs-static.s3.amazonaws.com/1572_7599552b60454033a0d5c5e6d2e34ffb.html
best,
Mathieu
2016-02-22 9:30 GMT+01:00 Michael Sumner <mdsumner at gmail.com>:
On Mon, 22 Feb 2016 at 19:13 Luca Candeloro <luca.candeloro at gmail.com>
wrote:
Dear all,
plotting graphs with given vertex coordinates is possible inside
plot function.
I would like to transform vilsualized edges into
SpatialLinesDataFrame, so
that they could be exported in .shp file...
Any suggestion?
Can you please provide a working igraph example that we can start with?
Do you want coordinates as seen in a particular plot, or can it be more
arbitrary?
Cheers, Mike.
thanks in advance,
Luca
[[alternative HTML version deleted]]