Skip to contents

Adds nodes (and optionally edges) of a gGraph to a ggplot as ggplot2::geom_sf() layers.

Usage

geom_ggraph(
  data = NULL,
  mapping = ggplot2::aes(),
  edges = FALSE,
  stat = "sf",
  position = "identity",
  na.rm = FALSE,
  show.legend = NA,
  ...
)

Arguments

data

a gGraph object.

mapping

aesthetics. Variables from the gGraph's node attributes may be used (e.g. aes(color = habitat)).

edges

logical; whether to draw edges. Defaults to FALSE.

stat, position, na.rm, show.legend, ...

forwarded to ggplot2::geom_sf().

Value

one or two ggplot layers (edges under nodes).

See also

Examples

library(ggplot2)
ggplot() +
  geom_ggraph(data = worldgraph.10k, aes(color = habitat), edges = TRUE, size = 0.3) +
  scale_color_manual(values = c(land = "grey70", sea = "lightblue", coast = "grey70")) +
  coord_sf(crs = "+proj=ortho +lat_0=40 +lon_0=-80") +
  theme_void()