r-tmap / tmap

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

Make `lwd` (and `lty`?) an aesthetic? #56

Closed joelgombin closed 2 years ago

joelgombin commented 8 years ago

I wonder whether it could be interesting and possible to make lwd (and possibly lty) an aesthetic in tm_borders. This would allow to make things like, e.g., discontinuities mapping (I'm not sure what the exact English term for that is). The difficulty however is that we would need a dataframe with one row per border, which usually doesn't come with a SpatialPolygons*. Or should we only use computed variables, such as in discontinuities mapping? But in that case we don't have values for external borders...

What do you think? For what it's worth, the cartography package has a discontinuity mapping function: https://github.com/Groupe-ElementR/cartography/blob/master/R/discLayer.R

mtennekes commented 8 years ago

Do you mean a separate border for any two adjacent polygons, or a separate border per polygon? In the first case, we'll indeed have to split the polygons into different line segments, which is indeed more difficult.

To make sure we're talking about the same thing: do you mean discontinuous cartograms, like http://giscommons.org/files/2009/08/6.7.gif?

joelgombin commented 8 years ago

I was indeed thinking of a border for any two adjacent polygons. Ideally this would operate on topological shapes, like topojson... Unfortunately I think this doesn't exist in R. cartography does this in a sort of hackish way, but it works... Le 11 avr. 2016 18:27, "mtennekes" notifications@github.com a écrit :

Do you mean a separate border for any two adjacent polygons, or a separate border per polygon? In the first case, we'll indeed have to split the polygons into different line segments, which is indeed more difficult.

To make sure we're talking about the same thing: do you mean discontinuous cartograms, like http://giscommons.org/files/2009/08/6.7.gif?

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/mtennekes/tmap/issues/56#issuecomment-208434713

mtennekes commented 8 years ago

Exactly, we could also use topojson I/O functions in R for the cartogram (https://github.com/mtennekes/tmap/issues/10).

Alternatively, you could make a function create_borders which takes an SPDF and finds borders, in this way:

joelgombin commented 8 years ago

AFAIK, there's isn't in R a class for topological shapefiles, and functions which read topojson files just spit out SPDFs, so that wouldn't help much.

The second way you suggest is more or less what cartography does, see https://github.com/Groupe-ElementR/cartography/blob/master/R/getBorders.R. Since cartography doesn't have any exotic dependency (actually only sp), should we just rely on their function?

joelgombin commented 8 years ago

Actually now that I think about it I think the cartography approach is maybe a bit too high-level for my taste, so maybe let's just:

mtennekes commented 8 years ago

The output of getBorders is obviously a SpatialLinesDataFrame, which can better be handled by tm_lines than tm_borders (that is, from a functional perspective).

We still need to let lty be an aesthetic in tm_lines.

mtennekes commented 2 years ago

Is already in tmap v4