knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

library(g2r)
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"))

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)

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
  ) 


devOpifex/g2r documentation built on Jan. 16, 2022, 12:36 a.m.