Warning

Maps are still experimental dot not perform very well.

The function fig_map accepts multiple dat formats. Beware of the size and level of details of these maps as they can seriously impact performances.

sf

The function accepts sf objects.

nc <- sf::st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source `/home/jp/R/x86_64-pc-linux-gnu-library/4.0/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27

g2() %>% 
  fig_map(asp(color = AREA, tooltip = NAME), map = nc) %>% 
  axis_hide() %>% 
  gauge_color(c("#0D0887FF", "#CC4678FF", "#F0F921FF")) %>% 
  tooltip(
    marker = FALSE,
    showTitle = FALSE
  ) %>% 
  aka(NAME_3, "Province")
# remotes::install_github("JohnCoene/globe4r")
data(cables, package = "globe4r")

g2() %>%
  fig_map(fill = "grey", asp(tooltip = name)) %>% 
  fig_path(data = cables, asp(X, Y, color = L1, shape = "smooth")) %>% 
  legend_color(FALSE) %>% 
  axis_hide() %>% 
  tooltip(
    showTitle = FALSE,
    marker = FALSE
  )

GADM

There is a convenience function to retrieve GADM data but will work with the raster::getData function as well.

belgium <- get_gadm_data("BEL", level = 3, keep = 0.2)
#> Registered S3 method overwritten by 'geojsonlint':
#>   method         from 
#>   print.location dplyr
#> Loading required package: sp

g2() %>% 
  fig_map(
    asp(tooltip = NAME_3),
    stroke = "#fff", fill = "gray", map = belgium
  ) %>% 
  axis_hide() %>% 
  tooltip(
    marker = FALSE,
    showTitle = FALSE
  ) %>% 
  aka(NAME_3, "Province")

Map data

There is also a get_map_data which resembles ggplot2::map_data.

china <- get_map_data("China")

g2() %>% 
  fig_map(map = china, asp(tooltip = level)) %>% 
  axis_hide() %>% 
  tooltip(
    marker = FALSE,
    showTitle = FALSE
  )