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

tmap_arrange fails with tmap_mode("view") & which crs in view mode? #874

Closed
marine-ecologist opened this issue May 7, 2024 · 2 comments
Closed

Comments

@marine-ecologist
Copy link

tmap_arrange throws a ! object 'lfmv' not found with tmap_mode("view").
Reproducible example and error below:

Rendering: /Users/XXXXX/tmp.Rmd
|...............................................................................................................................| 100% [unnamed-chunk-1]Error in print_tmap_arrange():
! object 'lfmv' not found
Backtrace:

  1. rmarkdown::render_site("/Users/XXXXXX/tmp.Rmd")
  2. generator$render(...)
  3. base::sapply(...)
  4. base::lapply(X = X, FUN = FUN, ...)
  5. rmarkdown (local) FUN(X[[i]], ...)
    ...
  6. knitr (local) value_fun(ev$value, ev$visible)
  7. knitr (local) fun(x, options = options)
  8. tmap:::knit_print.tmap_arrange(x, ...)
  9. tmap:::print_tmap_arrange(x, knit = TRUE, ..., options = options)
  10. base::do.call(kp, c(list(x = lfmv), args, list(options = options)))

---
title: "Untitled"
output: html_document
---

```{r}

library(leafsync)

data(World)
w1 <- qtm(World, projection = "+proj=eck4", title="Eckert IV")
w2 <- qtm(World, projection = 3857, title="Mercator")

tmap_mode("view")
tmap_arrange(w1, w2)



Thank you for all the assistance and updates! v4 is a great resource.
mtennekes added a commit that referenced this issue May 8, 2024
@mtennekes
Copy link
Member

The issue is fixed.

Thanks for this example, because it raises a follow-up question:

Currently, the projection (in v4 called crs) of the map is first determined by the tmap option "crs". If this is NA, then it will use the crs argument of tm_shape (or qtm). If that is unspecified, then it will take the crs of the shape (sf) object.

So the order of preference within tmap is:

tm_option crs > tm_shape crs > shape object crs

In plot mode, the tmap option crs is set to NA, but in view mode it is set to 4326. This means that in your example, w1 and w2 will produce the same map in view mode. This can be changed by:

tm_shape(World, crs = "+proj=eck4") + tm_polygons() + tm_options(crs = NA)

# or

qtm(World, projection = "+proj=eck4", title="Eckert IV") + tm_options(crs = NA)

We can change this. E.g.

tm_shape crs > tm_option crs > shape object crs

In your example this makes perfect sense, but in general I'm not convinced yet. What are your opinions @marine-ecologist @Nowosad @olivroy @xtimbeau @ar-puuk @LenLon ?

@mtennekes mtennekes changed the title tmap_arrange fails with tmap_mode("view") tmap_arrange fails with tmap_mode("view") & which crs in view mode? May 8, 2024
@Nowosad
Copy link
Member

Nowosad commented May 9, 2024

I think that the current approach is fine.

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

3 participants