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

tmap_grob creates an empty plot #542

Open Nowosad opened 3 years ago

Nowosad commented 3 years ago

tmap_grob() opens a new graphic device, which creates an empty plot (both in RStudio, but also in other sessions; see reprex below). It is a minor inconvenience, but hopefully it could be easily fixed.

library(tmap)
data(World)

tm1 = tm_shape(World) + tm_polygons("well_being", 
                                    title = "Well-being",
                                    palette = "RdYlGn")

tm1_grob = tmap_grob(tm1)
#> Note that the aspect ratio for which the grob has been generated is 1.4

Created on 2021-01-23 by the reprex package (v0.3.0)

mtennekes commented 3 years ago

Yes, I am aware of it. I already found a way how to solve it, which will be applied in v4. If it isn't too much effort I'll fix it in v3 as well, but it has low priority.

FelipeCarrillo commented 1 year ago

Is this the same issue as below ?:

tmap_mode("view")
qtm(World)

The map gets displayed on my browser but an R empty device gets invoked as well.

olivroy commented 7 months ago

@mtennekes , another failure in Spatial Data Science with R was the absence of tmap_grob(), do you plan to add it back for tmap v4?

pol_pres15$sps1 <- sps[,mr]
tm1 <- tm_shape(pol_pres15) +
          tm_fill("sps1", title = "Shortest path\ncount")
coords[mr] |> 
    st_distance(coords) |> 
    c() |> 
    (function(x) x/1000)() |> 
    units::set_units(NULL) -> pol_pres15$dist_52
library(ggplot2)
g1 <- ggplot(pol_pres15, aes(x = sps1, y = dist_52)) +
        geom_point() +
        xlab("Shortest path count") +
        ylab("km distance")
gridExtra::grid.arrange(tmap_grob(tm1), g1, nrow=1)

This is in Chapter 14 https://r-spatial.org/book/14-Areal.html#fig-shortestpath