Closed joelgombin closed 2 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?
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
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:
spdep::poly2nb
to determine which polygons are adjacentrgeos::gIntersection
to find the intersection. Only keep the spatial lines.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?
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:
getBorders
function in a tmap
functionlwd
and lty
parameters to be astehetics in tm_borders
. If a user wants to emulate the behaviour of cartography::discLayer
he can then easily do it by hand, but that would also allow other use cases.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
.
Is already in tmap v4
I wonder whether it could be interesting and possible to make
lwd
(and possiblylty
) an aesthetic intm_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 aSpatialPolygons*
. 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