r-tmap / tmap

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

remove_overlap = T and show_legend = T produce errors #816

Open aterhorst opened 9 months ago

aterhorst commented 9 months ago

My r-script which worked in the past is now broken.

p4 <- tm_shape(aoi, bbox = c(c(18.423, -34.20), c(18.505, -34.16))) +
  tm_graticules(col ="lightgray", n.x = 5, n.y = 4) +
  tm_borders(col = "gray", lwd = 0.75) +
  tm_shape(samples %>% mutate(facies = as.character(facies))) +
  tm_dots(size = 0.3,
          palette = sample_cols,
          col = "facies",
          shape = "method",
          title = "Acoustic facies") +
  tm_text("sample", ymod = 0.6, xmod = 0.3, size = 0.6, remove.overlap = T) +
  tm_shape(roman_rock) +
  tm_text(text = "label", size = 0.8, ymod = -0.6) +
  tm_shape(coastline) +
  tm_lines(col = "black") +
  tm_legend(position = c("right", "top")) +
  tm_layout(frame = TRUE, 
            inner.margins = 0, 
            legend.width = 0.5,
            frame.lwd = 2) +
  tm_scale_bar()

used to work but now generates this error:

p4
Error in if (gpl$text.remove.overlap) { : the condition has length > 1

If I remove remove_overlap = T, I get a plot, but the text labels are on top of each other.

When I add legend_show = T to tm_layout as follows:

p4 <- tm_shape(aoi, bbox = c(c(18.423, -34.20), c(18.505, -34.16))) +
  tm_graticules(col ="lightgray", n.x = 5, n.y = 4) +
  tm_borders(col = "gray", lwd = 0.75) +
  tm_shape(samples %>% mutate(facies = as.character(facies))) +
  tm_dots(size = 0.3,
          palette = sample_cols,
          col = "facies",
          shape = "method",
          title = "Acoustic facies") +
  tm_text("sample", ymod = 0.6, xmod = 0.3, size = 0.6, remove.overlap = T) +
  tm_shape(roman_rock) +
  tm_text(text = "label", size = 0.8, ymod = -0.6) +
  tm_shape(coastline) +
  tm_lines(col = "black") +
  tm_legend(position = c("right", "top")) +
  tm_layout(frame = TRUE, 
            legend.show = T,
            inner.margins = 0, 
            legend.width = 0.5,
            frame.lwd = 2) +
  tm_scale_bar()

I get this error:

p4
Error in !any.legend || !legend.show : 
  'length = 4' in coercion to 'logical(1)'

Removing remove_overlap = T makes no difference. I get the same error. However, ditching legend_show = T, I get a plot with overlapping labels, sadly.

aterhorst commented 9 months ago

Note I installed Tmap version 4, but it does not have all the functionality of Tmap version 3 (I refer to tm_iso specifically) and so reverted to tmap version 3.