Is there a geom_text_repel equivalent to repel dots/text in tmap?

47 views Asked by At

Is there a way to repel dots and text in the tmap package similar to the ggrepel package's function geom_text_repel for STATIC maps? The dynamic map has a clustering option, but I can't find something to work when tmap_mode is set to plot.

A simple reproducible example from the spData package using cycle_hire data set:

library(spData)
data(cycle_hire)
tmap_mode("plot")

cycle_hire %>% 
  arrange(desc(geometry)) %>% 
  slice(20:50) %>% 
  tm_shape() +
  tm_dots(size = 3, col = "navy") +
  tm_text("id", col = "white")

I'm not concerned about a base tile for this example. I'm just hoping to find a way to repel dots and text to the same new position with a line segment pointing to the original coordinate. There may be a better way to get clustered dots from the data set, but I just sliced to observations 20:50, which had enough close together to, hopefully, demonstrate the challenge.

The resulting plot/map produced looks like this: enter image description here

I'm not concerned with making this pretty as I know how to do that already. I know reducing the dot size can help reduce overlap, but that's not a solution I need. It's just as raw of an example as possible to try to find a way to repel overlapping dots/text.

0

There are 0 answers