r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
862 stars 121 forks source link

flux cartography #4

Closed joelgombin closed 2 years ago

joelgombin commented 9 years ago

e.g. http://rgeomatic.hypotheses.org/351

mtennekes commented 9 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.

joelgombin commented 9 years ago

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...

mtennekes commented 8 years ago

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:

  1. Process the graph data (e.g. from igraph), and convert the edges to a SLDF with curved lines.
  2. Enhance tm_lines and process_lines so that is can handle endpoints drawings.
  3. Create tm_flow, which is a wrapper of tm_lines, where endpoints are by default enabled.
  4. As for drawing the endpoints, we need to four parameters: the coordinates (which is the last pair of coordinates per 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.

Robinlovelace commented 8 years ago

This looks exciting - will incorporate in my teaching materials when released to CRAN!

joelgombin commented 8 years ago

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.

mtennekes commented 8 years ago

@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.

carbonmetrics commented 6 years ago

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?

Robinlovelace commented 6 years ago

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

carbonmetrics commented 6 years ago

Thanks! I think I am stuck at converting the extracted edge list to to a sf object.

Robinlovelace commented 6 years ago

Note that function was designed to run on geographic route networks so may not be appropriate for your application in its current form.

mtennekes commented 2 years ago

Cleaning up all issues that are not relevant for the first release of tmap v4.