knitr::opts_chunk$set(
  collapse = TRUE,
  fig.width = 8,
  comment = "#>"
)
hook_output <- knitr::knit_hooks$get("output")
knitr::knit_hooks$set(output = function(x, options) {
   lines <- options$output.lines
   if (is.null(lines)) {
     return(hook_output(x, options))  # pass to default hook
   }
   x <- unlist(strsplit(x, "\n"))
   more <- "..."
   if (length(lines)==1) {        # first n lines
     if (length(x) > lines) {
       # truncate the output, but add ....
       x <- c(head(x, lines), more)
     }
   } else {
     x <- c(more, x[lines], more)
   }
   # paste these lines together
   x <- paste(c(x, ""), collapse = "\n")
   hook_output(x, options)
 })
library(tmap)
library(tmap.networks)
tmap_options(scale = 0.75)

With tmap.networks network visualizations can be made. It will handle sfnetwork objects (from the package sfnetworks) natively.

library(sfnetworks)
library(tmap.networks)

(sfn = as_sfnetwork(roxel))

Besides this new spatial data class "sfnetwork", this package also features new map layers, albeit very basic so far:

tm_shape(sfn) +
    tm_network()
tm_shape(sfn) +
    tm_edges(col = "type", lwd = 4) +
    tm_nodes()


r-tmap/tmap documentation built on June 1, 2025, 1:56 p.m.