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.
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.
You can install the development version of overedge like so:
remotes::install_github("elipousson/overedge")
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.
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)
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")
nc_squares <- st_square(nc, inscribed = TRUE)
nc_map +
geom_sf(data = nc_squares, fill = NA, color = "red")
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
)