Skip to content

✂️🗺 A R package of miscellaneous map making functions.

License

Notifications You must be signed in to change notification settings

elipousson/overedge

Repository files navigation

overedge

CRAN status Lifecycle: experimental License: MIT Codecov test coverage

The goal of overedge is to provide useful functions for making maps with R. This is a collection of miscellaneous functions primarily for working with ggplot2 and sf.

Update (2022 July 25)

I’m in the process of migrating all functions from overedge into three more focused packages:

  • sfext: sf utilities and read/write functions
  • getdata: data access and formatting functions
  • maplayer: ggplot2 mapping and theme functions

None of these packages depend on overedge. getdata depends on sfext and maplayer depends on both getdata and sfext. I expect overedge to develop into a “tidyverse” style package that loads all three packages at once but I will continue to maintain the packages separately for ease of testing and maintenance. In the interim, I do not recommend using overedge.

Installation

You can install the development version of overedge like so:

remotes::install_github("elipousson/overedge")

Examples

overedge currently provides a variety of functions for accessing spatial data, modifying simple feature or bounding box objects, and creating or formatting maps with ggplot2.

Make icon maps with sf objects and ggplot2

layer_icon wraps ggsvg::geom_point_svg() to provide an convenient way to make icon maps.

You can create maps using a single named icon that matches one of the icons in map_icons.

library(overedge)
library(ggplot2)
library(sf)

nc <- st_read(system.file("shape/nc.shp", package = "sf"))
nc <- st_transform(nc, 3857)
theme_set(theme_void())

nc_map <-
  ggplot() +
  geom_sf(data = nc)

nc_map +
  layer_icon(data = nc, icon = "point-start", size = 8)

You can also use an icon column from the provided sf object.

nc$icon <- rep(c("1", "2", "3", "4"), nrow(nc) / 4)

nc_map +
  layer_icon(data = nc, size = 5)

Check map_icons to see all supported icon names.

head(map_icons)

Scale and rotate sf objects

st_scale_rotate() is a convenience function for apply affine transformations to sf objects.

nc_rotated <- st_scale_rotate(nc, scale = 0.5, rotate = 15)

nc_map +
  geom_sf(data = nc_rotated, fill = NA, color = "red")

Create inscribed squares in sf objects

nc_squares <- st_square(nc, inscribed = TRUE)

nc_map +
  geom_sf(data = nc_squares, fill = NA, color = "red")

Add a neatline to a map

layer_neatline() hides major grid lines and axis label by default. The function is useful to draw a neatline around a map at a set aspect ratio.

nc_map +
  layer_neatline(
    data = nc,
    asp = "6:4",
    color = "gray60", size = 2, linetype = "dashed"
  )

layer_neatline() can also be used to focus on a specific area of a map with the option to apply a buffer as a distance or ratio of the diagonal distance for the input data. The label_axes and hide_grid parameters will not override a set ggplot theme.

theme_set(theme_minimal())

nc_map +
  layer_neatline(
    data = nc[1, ],
    diag_ratio = 0.5,
    asp = 1,
    color = "black",
    label_axes = "--EN",
    hide_grid = FALSE
  )

About

✂️🗺 A R package of miscellaneous map making functions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages