tmap only plotting first polygon in sf geometry column

301 views Asked by At

tmap is only plotting the first polygon in an sf geometry column, but plot() gets them all.

Some github issues for tmap and leaflet mention something similar, but they were related to names in an sf geometry column (which the World data doesn't have). Additionally, the problem was fixed in both packages.

Here's a reprex using the first example in the tmap Getting Started vignette.

library(tmap)
#> Warning: package 'tmap' was built under R version 3.5.3
data("World")

# tmap only plots one polygon
tm_shape(World) +
    tm_polygons("HPI")

# plot gets them all
plot(World["HPI"])

Created on 2020-10-15 by the reprex package (v0.3.0)

devtools::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/Chicago             
#>  date     2020-10-15                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package      * version  date       lib source        
#>  abind          1.4-5    2016-07-21 [1] CRAN (R 3.5.2)
#>  assertthat     0.2.1    2019-03-21 [1] CRAN (R 3.5.3)
#>  backports      1.1.10   2020-09-15 [1] RSPM (R 3.5.3)
#>  base64enc      0.1-3    2015-07-28 [1] CRAN (R 3.5.2)
#>  callr          3.5.1    2020-10-13 [1] RSPM (R 3.5.1)
#>  class          7.3-14   2015-08-30 [2] CRAN (R 3.5.1)
#>  classInt       0.4-3    2020-04-07 [1] CRAN (R 3.5.3)
#>  cli            2.1.0    2020-10-12 [1] RSPM (R 3.5.1)
#>  codetools      0.2-15   2016-10-05 [2] CRAN (R 3.5.1)
#>  crayon         1.3.4    2017-09-16 [1] CRAN (R 3.5.3)
#>  crosstalk      1.1.0.1  2020-03-13 [1] CRAN (R 3.5.3)
#>  curl           4.3      2019-12-02 [1] CRAN (R 3.5.3)
#>  DBI            1.1.0    2019-12-15 [1] CRAN (R 3.5.3)
#>  desc           1.2.0    2018-05-01 [1] CRAN (R 3.5.3)
#>  devtools       2.3.2    2020-09-18 [1] RSPM (R 3.5.3)
#>  dichromat      2.0-0    2013-01-24 [1] CRAN (R 3.5.2)
#>  digest         0.6.25   2020-02-23 [1] CRAN (R 3.5.3)
#>  dplyr          1.0.2    2020-08-18 [1] RSPM (R 3.5.3)
#>  e1071          1.7-3    2019-11-26 [1] CRAN (R 3.5.3)
#>  ellipsis       0.3.1    2020-05-15 [1] RSPM (R 3.5.3)
#>  evaluate       0.14     2019-05-28 [1] CRAN (R 3.5.3)
#>  fansi          0.4.1    2020-01-08 [1] CRAN (R 3.5.3)
#>  fs             1.5.0    2020-07-31 [1] RSPM (R 3.5.3)
#>  generics       0.0.2    2018-11-29 [1] CRAN (R 3.5.3)
#>  glue           1.4.2    2020-08-27 [1] RSPM (R 3.5.3)
#>  highr          0.8      2019-03-20 [1] CRAN (R 3.5.3)
#>  htmltools      0.5.0    2020-06-16 [1] RSPM (R 3.5.3)
#>  htmlwidgets    1.5.2    2020-10-03 [1] RSPM (R 3.5.3)
#>  httr           1.4.2    2020-07-20 [1] CRAN (R 3.5.1)
#>  KernSmooth     2.23-15  2015-06-29 [2] CRAN (R 3.5.1)
#>  knitr          1.30     2020-09-22 [1] RSPM (R 3.5.3)
#>  lattice        0.20-35  2017-03-25 [2] CRAN (R 3.5.1)
#>  leafem         0.1.3    2020-07-26 [1] CRAN (R 3.5.1)
#>  leaflet        2.0.3    2019-11-16 [1] CRAN (R 3.5.3)
#>  leafsync       0.1.0    2019-03-05 [1] CRAN (R 3.5.3)
#>  lifecycle      0.2.0    2020-03-06 [1] CRAN (R 3.5.3)
#>  lwgeom         0.2-5    2020-06-12 [1] RSPM (R 3.5.3)
#>  magrittr       1.5      2014-11-22 [1] CRAN (R 3.5.3)
#>  memoise        1.1.0    2017-04-21 [1] CRAN (R 3.5.3)
#>  mime           0.9      2020-02-04 [1] CRAN (R 3.5.3)
#>  pillar         1.4.6    2020-07-10 [1] CRAN (R 3.5.1)
#>  pkgbuild       1.1.0    2020-07-13 [1] CRAN (R 3.5.1)
#>  pkgconfig      2.0.3    2019-09-22 [1] CRAN (R 3.5.3)
#>  pkgload        1.1.0    2020-05-29 [1] RSPM (R 3.5.3)
#>  png            0.1-7    2013-12-03 [1] CRAN (R 3.5.2)
#>  prettyunits    1.1.1    2020-01-24 [1] CRAN (R 3.5.3)
#>  processx       3.4.4    2020-09-03 [1] RSPM (R 3.5.3)
#>  ps             1.3.4    2020-08-11 [1] RSPM (R 3.5.3)
#>  purrr          0.3.4    2020-04-17 [1] CRAN (R 3.5.3)
#>  R6             2.4.1    2019-11-12 [1] CRAN (R 3.5.3)
#>  raster         3.3-13   2020-07-17 [1] RSPM (R 3.5.3)
#>  RColorBrewer   1.1-2    2014-12-07 [1] CRAN (R 3.5.2)
#>  Rcpp           1.0.5    2020-07-06 [1] RSPM (R 3.5.3)
#>  remotes        2.2.0    2020-07-21 [1] CRAN (R 3.5.1)
#>  rlang          0.4.7    2020-07-09 [1] RSPM (R 3.5.3)
#>  rmarkdown      2.4      2020-09-30 [1] RSPM (R 3.5.3)
#>  rprojroot      1.3-2    2018-01-03 [1] CRAN (R 3.5.3)
#>  sessioninfo    1.1.1    2018-11-05 [1] CRAN (R 3.5.3)
#>  sf             0.9-6    2020-09-13 [1] RSPM (R 3.5.3)
#>  sp             1.4-2    2020-05-20 [1] RSPM (R 3.5.3)
#>  stars          0.4-3    2020-07-08 [1] CRAN (R 3.5.1)
#>  stringi        1.5.3    2020-09-09 [1] RSPM (R 3.5.3)
#>  stringr        1.4.0    2019-02-10 [1] CRAN (R 3.5.3)
#>  testthat       2.3.2    2020-03-02 [1] CRAN (R 3.5.3)
#>  tibble         3.0.3    2020-07-10 [1] RSPM (R 3.5.3)
#>  tidyselect     1.1.0    2020-05-11 [1] RSPM (R 3.5.3)
#>  tmap         * 3.2      2020-09-15 [1] RSPM (R 3.5.3)
#>  tmaptools      3.1      2020-07-01 [1] CRAN (R 3.5.1)
#>  units          0.6-7    2020-06-13 [1] RSPM (R 3.5.3)
#>  usethis        1.6.3    2020-09-17 [1] RSPM (R 3.5.3)
#>  vctrs          0.3.4    2020-08-29 [1] RSPM (R 3.5.3)
#>  viridisLite    0.3.0    2018-02-01 [1] CRAN (R 3.5.3)
#>  withr          2.3.0    2020-09-22 [1] RSPM (R 3.5.3)
#>  xfun           0.18     2020-09-29 [1] RSPM (R 3.5.3)
#>  XML            3.99-0.3 2020-01-20 [1] CRAN (R 3.5.3)
#>  xml2           1.3.2    2020-04-23 [1] CRAN (R 3.5.3)
#>  yaml           2.2.1    2020-02-01 [1] CRAN (R 3.5.3)
#> 
#> [1] C:/R_packages
#> [2] C:/Program Files/R/R-3.5.1/library
1

There are 1 answers

0
piaHZERA On

I was with the same problem. So, I upgraded to the recent version of the tmap package and R version. The problem was fixed.

R version 4.1.0 (2021-05-18) Tmap package version 3.3-1