Skip to contents

The layers that draw an rpic_sf() data frame as pic drew it, to add to a ggplot() — alone or over a basemap. Shapes go through ggplot2::geom_sf() with their fill and stroke columns (pic colours are hex strings already, so the scales are identity scales); every text (geopic_kind "text" and "title") is a label at its point through ggplot2::geom_sf_text(), justified and turned as pic placed it — the geopic_anchor compass becomes hjust/vjust (above puts the point at the label's bottom, ljust at its left) and geopic_rotation becomes angle; a label written bold, italic or mono keeps its face (geopic_font_weight, geopic_font_style, geopic_font_family become fontface and the "mono" family). ggplot2::coord_sf() with clip = "off" completes the list, so labels at the drawing's edge are not cut.

Usage

rpic_layers(x, ..., linewidth = 0.4, text_size = 3)

Arguments

x

a georeferenced drawing: an rpic_sf() data frame, or anything rpic_sf() takes — a pic() object or pic source (then ... are its georeferencing arguments: anchor, scale, bearing, frame, features, ...).

...

passed to rpic_sf() when x is pic source; an error otherwise.

linewidth

line width of the shapes, in ggplot2 units (mm). NULL draws each shape at pic's own width (the stroke_width column, points, 0.8 by default).

text_size

size of the labels, in ggplot2 units (mm).

Value

a list of ggplot2 layers, scales and a coord_sf().

Details

The result is a list of layers and scales: add it to a plot with +. Layers added before it (a basemap) are drawn under the drawing, layers added after it on top; axes and theme are the plot's own — vignette("maps") shows the longitude/latitude grid with theme_minimal(), autoplot.rpic_source() hides it with theme_void().

Requirements

Needs ggplot2 and sf.

See also

autoplot.rpic_source() for the one-call map; rpic_sf() for the data and its columns; add_rpic() for an interactive MapLibre map.

Examples

if (requireNamespace("ggplot2", quietly = TRUE) &&
    requireNamespace("sf", quietly = TRUE)) {
  radius <- pic('geo_lon = -34.8711; geo_lat = -8.0631; geo_scale = 1000
  C: circle rad 2 at (0, 0) dashed fill 0.97
  line from C.c to C.e thin
  "2 km" above at 0.5 <C.c, C.e>') |>
    rpic_sf()
  ggplot2::ggplot() + rpic_layers(radius) + ggplot2::theme_minimal()
}
#> Warning: 'x' is NULL so the result will be NULL