Learn R Programming

sfnetworks (version 0.4.1)

autoplot: Plot sfnetwork geometries with ggplot2

Description

Plot the geometries of an object of class sfnetwork automatically as a ggplot object. Use this method without the .sfnetwork suffix and after loading the ggplot2 package.

Usage

autoplot.sfnetwork(object, ...)

Arguments

object

An object of class sfnetwork.

...

Ignored.

Details

See autoplot.

Examples

Run this code
# NOT RUN {
library(ggplot2, quietly = TRUE)
library(sf, quietly = TRUE)

net = as_sfnetwork(roxel) %>%
  st_transform(3035)

# Quick overview of the network in ggplot style.
autoplot(net)

# Other ggplot elements can be added.
points = net %>%
  st_bbox() %>%
  st_as_sfc() %>%
  st_sample(10, type = 'random') %>%
  st_set_crs(3035) %>%
  st_cast('POINT')

autoplot(net) +
  # The theme can be customized
  theme_minimal() +
  # Labels can be added
  labs(title = 'Nice ggplot') +
  # And extra sf layers can be included
  geom_sf(data = points, color = 'red', size = 2)

# }

Run the code above in your browser using DataLab