Skip to contents

Use ggforce::geom_mark_rect(), ggforce::geom_mark_circle(), ggforce::geom_mark_ellipse(), or ggforce::geom_mark_hull() to annotate simple feature objects. This function modifies the geometry and sets the stat to "st_coordinates" to make it easy to use these annotation geoms with simple feature objects.

Usage

layer_show_mark(
  data,
  fn = NULL,
  mapping = NULL,
  label_col = NULL,
  desc_col = NULL,
  geom = NULL,
  cast = TRUE,
  expand = ggplot2::unit(5, "mm"),
  radius = expand,
  ...
)

Arguments

data

A sf, sfc, or bbox object that can be converted with overedge::as_sf

fn

Function to apply to data before passing to geom, typically a predicate or filter to define area for annotation. A filter can also be passed to any of the ggforce functions using the filter aesthetic. Default: NULL

mapping

Aesthetic mapping to pass to geom, Default: NULL

geom

geom to use for layer ("rect", "circle", "ellipse", or "hull"), Default: NULL

cast

If TRUE, cast MULTIPOLYGON and POLYGON data to POINT; defaults to TRUE.

expand

defaults to ggplot2::unit(5, "mm")

radius

defaults to expand

...

Additional parameters passed to ggforce annotation geoms.

Geometry conversion for MULTIPOLYGON or POLYGON data

If cast is FALSE and the data geometry type is MULTIPOLYGON or POLYGON, the annotation uses a centroid for the annotation geometry. If cast is TRUE, the data is converted to POINT geometry using sf::st_cast() and the modified geometry passed on to selected geom.

Setting label and description

Labels and descriptions can be included in the aesthetic mapping for the layer consistent with the standard documented approaches for all four functions.

Labels and descriptions also can be set in two non-standard ways:

  • Setting label_col and/or or desc_col to character strings with the column names for labels and/or descriptions

  • Setting label_col and/or desc_col with the value of the label/description

If the first approach is used, label_col and desc_col can also can be created or modified by a function provided to the fn parameter. Otherwise, the columns must be present in the data to work. If the second approach is used, the length and order of vector provided to label_col and/or desc_col must match that length and order of the data (after the fn is applied).

Examples

if (FALSE) {
if (interactive()) {
  library(ggplot)
  library(overedge)

  ggplot() +
    layer_location_data(
      data = "neighborhoods",
      package = "mapbaltimore"
    ) +
    layer_show_mark(
      data = get_location(
        type = "council district",
        name = "District 12",
        package = "mapbaltimore"
      ),
      geom = "hull",
      color = "red",
      size = 1.5
    )
}
}