Skip to content

Upper bound interval turns to NA when formatting is applied #1208

@jonas-karlsson

Description

@jonas-karlsson

When applying a label format to the interval, the upper bound becomes NA. Lower bound behaves as expected.

library(tmap)

tm_shape(World) +
  tm_polygons(
    fill = "HPI",
    fill.scale = tm_scale_intervals()
  ) +
  tm_title("No label format applied")
#> [tip] Consider a suitable map projection, e.g. by adding `+ tm_crs("auto")`.
#> This message is displayed once per session.

tm_shape(World) +
  tm_polygons(
    fill = "HPI",
    fill.scale = tm_scale_intervals(
      label.format = list(fun = scales::percent)
    )
  ) +
  tm_title("Label format scales::percent applied")

sessionInfo()
#> R version 4.5.2 (2025-10-31)
#> Platform: aarch64-apple-darwin25.0.0
#> Running under: macOS Tahoe 26.0.1
#> 
#> Matrix products: default
#> BLAS:   /opt/homebrew/Cellar/openblas/0.3.30/lib/libopenblasp-r0.3.30.dylib 
#> LAPACK: /opt/homebrew/Cellar/r/4.5.2/lib/R/lib/libRlapack.dylib;  LAPACK version 3.12.1
#> 
#> locale:
#> [1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8
#> 
#> time zone: Europe/Zurich
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] tmap_4.2.0.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] s2_1.1.9           class_7.3-23       lwgeom_0.2-14      KernSmooth_2.23-26
#>  [5] lattice_0.22-7     digest_0.6.37      magrittr_2.0.4     RColorBrewer_1.1-3
#>  [9] evaluate_1.0.5     grid_4.5.2         fastmap_1.2.0      e1071_1.7-16      
#> [13] leafsync_0.1.0     DBI_1.2.3          scales_1.4.0       crosstalk_1.2.2   
#> [17] cols4all_0.10      XML_3.99-0.19      codetools_0.2-20   abind_1.4-8       
#> [21] cli_3.6.5          rlang_1.1.6        units_1.0-0        tmaptools_3.3     
#> [25] reprex_2.1.1       base64enc_0.1-3    withr_3.0.2        yaml_2.3.10       
#> [29] leaflegend_1.2.1   tools_4.5.2        raster_3.6-32      parallel_4.5.2    
#> [33] maptiles_0.10.0    colorspace_2.1-2   spacesXYZ_1.6-0    logger_0.4.1      
#> [37] R6_2.6.1           png_0.1-8          proxy_0.4-27       lifecycle_1.0.4   
#> [41] classInt_0.4-11    leaflet_2.2.3      fs_1.6.6           htmlwidgets_1.6.4 
#> [45] terra_1.8-80       data.table_1.17.8  glue_1.8.0         Rcpp_1.1.0        
#> [49] sf_1.0-21          xfun_0.54          knitr_1.50         farver_2.1.2      
#> [53] htmltools_0.5.8.1  rmarkdown_2.30     leafem_0.2.5       wk_0.9.4          
#> [57] compiler_4.5.2     sp_2.2-0           stars_0.6-8

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

EDIT. Wrapping the label.format in tm_label_format produces the same output

library(tmap)

tm_shape(World) +
  tm_polygons(
    fill = "HPI",
    fill.scale = tm_scale_intervals(
      label.format = tm_label_format(
        fun = scales::percent
      )
    )
  ) +
  tm_title("Label format scales::percent applied")
#> [tip] Consider a suitable map projection, e.g. by adding `+ tm_crs("auto")`.
#> This message is displayed once per session.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions