knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) library(g2r)
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.
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 )
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")
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 )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.