tmap_arrange fails with tmap_mode("view") & which crs in view mode?
Closed this issue · 2 comments
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 inprint_tmap_arrange()
:
! object 'lfmv' not found
Backtrace:
- rmarkdown::render_site("/Users/XXXXXX/tmp.Rmd")
- generator$render(...)
- base::sapply(...)
- base::lapply(X = X, FUN = FUN, ...)
- rmarkdown (local) FUN(X[[i]], ...)
...- knitr (local) value_fun(ev$value, ev$visible)
- knitr (local) fun(x, options = options)
- tmap:::knit_print.tmap_arrange(x, ...)
- tmap:::print_tmap_arrange(x, knit = TRUE, ..., options = options)
- 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.
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 ?
I think that the current approach is fine.