Closed joelgombin closed 2 years ago
Hi Joel, maybe you've thought of this too, but I think the most elegant type of input for the tm_flow
would be an igraph
object, where the nodes can be mapped to e.g. polygons.
tm_shape(World) +
tm_polygons() +
tm_flow(world_migration_graph, id="iso_a3")
The id
variable serves as identifier for the polygons, whose values correspond to the vertices of the graphs.
Yes, that's exactly what I'm working on. The tricky part is to get something visually not too awful, especially since igraph
doesn't handle the arrow size. So I'm trying something along the lines of http://rgeomatic.hypotheses.org/351, but it is not very efficient...
FYI, I'm rewriting the process_x functions a bit to make them more efficient. See branch https://github.com/mtennekes/tmap/tree/text_aes, where I also included text aesthetics size and color.
As for the flow maps: I have some new ideas to we can implement them:
igraph
), and convert the edges to a SLDF with curved lines.tm_lines
and process_lines
so that is can handle endpoints drawings. tm_flow
, which is a wrapper of tm_lines
, where endpoints are by default enabled.Line
object), the direction (which can also be extracted from the Line
objects), the size (to be configured by the user), and the shape of the endpoint polygon (by default a triangle).This will lead to the following work flow:
fm <- create_flowmap(my_igraph_object, shp=World, shp.id="iso_a3")
tm_shape(World) +
tm_polygons() +
tm_shape(fm) +
tm_flow(col="var1", lwd="var2", endpoint.size=3)
In create_flowmap
, shp
could be any Spatial
object from which we can extract coordinates. It is also important to know the target projection in order to properly set the curvature of the arcs.
@joelgombin: let me know if this approach sounds ok to you, and if this fits your attempt to implement them.
This looks exciting - will incorporate in my teaching materials when released to CRAN!
Sorry @mtennekes I didn't answer earlier - my son was born a few days before your post so I kinda list track. Sounds great, yes. I hadn't thought of using SLDF but seems like a good point. I think a fair deal of emphasis should also be put to pre-processing the graph data, for example with (smart?) aggregation, because once the data is large, plotting it raw becomes unbearable.
@joelgombin Congrats with your son!
It would be nice indeed to add functionality to (partially) cluster the arrows. However, this is far from straightforward. Does anyone know which algorithms we could use?
For the time being, we could stick to the 'simple' flow maps with curved arcs.
I would like to plot an igraph object onto a map using tmap, like this, and found this thread; is the flowmap a feature that is in the pipeline?
Info that may help: stplanr::SpatialLinesNetwork()
creates a spatial object that has an igraph
object built-in, for example as illustrated in the image in this issue: https://github.com/ATFutures/dodgr/issues/56#issuecomment-395134949
Thanks! I think I am stuck at converting the extracted edge list to to a sf object.
Note that function was designed to run on geographic route networks so may not be appropriate for your application in its current form.
Cleaning up all issues that are not relevant for the first release of tmap v4.
e.g. http://rgeomatic.hypotheses.org/351