tmap icon indicating copy to clipboard operation
tmap copied to clipboard

tmap_save() compression parameter

Open Rapsodia86 opened this issue 1 month ago • 3 comments

Hi @mtennekes, I am exporting graphics to "tiff", but I do not see parameter for compression. Does it exist actually? My outputs are now uncompressed (each 40MB), a bit too big. And I need them in "tiff" format for publication. I can compress them externally as another step, but would like to do it thru tmap_save.

Thanks, Monika

Rapsodia86 avatar Nov 06 '25 15:11 Rapsodia86

You can use the compression argument of the tiff device:

library(tmap)
library(sf)
#> Linking to GEOS 3.13.0, GDAL 3.10.3, PROJ 9.6.0; sf_use_s2() is TRUE
library(spData)
tm = tm_shape(nz) +
    tm_polygons() +
    tm_text("Name", fontface = "italic")
tm


tmap_save(tm, filename = "tmap1.tiff", width = 800, height = 600)
#> Map saved to /home/jn/tmap1.tiff
#> Resolution: 800 by 600 pixels
#> Size: 2.666667 by 2 inches (300 dpi)
tmap_save(tm, filename = "tmap2.tiff", width = 800, height = 600,
          compression = "lzw")
#> Map saved to /home/jn/Tmap2.tiff
#> Resolution: 800 by 600 pixels
#> Size: 2.666667 by 2 inches (300 dpi)

file.size("tmap1.tiff")
#> [1] 1440212
file.size("tmap2.tiff")
#> [1] 69660

Created on 2025-11-06 with reprex v2.1.1

Nowosad avatar Nov 06 '25 16:11 Nowosad

Works, thank you! I asked, because I could not find "compression" parameter in the docs: https://cran.r-project.org/web/packages/tmap/tmap.pdf

Rapsodia86 avatar Nov 06 '25 17:11 Rapsodia86

@mtennekes -- please confirm that ... can be used to provide additional device arguments to tmap_save()? If this is true, then we should improve the help file of that function.

Nowosad avatar Nov 07 '25 16:11 Nowosad