Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove_overlap = T and show_legend = T produce errors #816

Open
aterhorst opened this issue Dec 6, 2023 · 1 comment
Open

remove_overlap = T and show_legend = T produce errors #816

aterhorst opened this issue Dec 6, 2023 · 1 comment

Comments

@aterhorst
Copy link

aterhorst commented Dec 6, 2023

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
Copy link
Author

aterhorst commented Dec 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant