MyNixOS website logo
Description

Donut Maps with 'sf', 'ggplot2', and 'leaflet'.

Create donut charts positioned on maps from tidy data. The package provides helpers to compute donut polygon geometries, optional origin-destination flow lines, ready-to-use 'ggplot2' map layers, and interactive 'leaflet' widgets.

DonutMap

DonutMap hex logo

R-CMD-check pkgdown pkgdown site R >= 4.1.0 License: MIT

DonutMap is an R package for drawing donut charts on static and interactive maps with sf, ggplot2, and leaflet.

Website: https://aureliennicosiaulaval.github.io/DonutMap/

The package is inspired by mtennekes/donutmaps, but starts from a simpler tidy-data interface and avoids the older odf/tmap workflow.

Online examples

The pkgdown site includes a getting-started article and a dedicated example gallery available from the Examples menu.

Installation

# From GitHub
devtools::install_github("AurelienNicosiaULaval/DonutMap")

# From this local repository
devtools::install()

Main functions

donut_map() creates a static ggplot2 map with optional coloured curved trajectories and arrows.

donut_leaflet() creates an interactive leaflet map with clickable donut segments, popups, hover labels, legends, and optional coloured curved trajectories with directional arrowheads. It builds the interactive donut symbols in EPSG:3857 by default and disables Leaflet simplification for donut polygons so sector separators stay visually regular.

donut_polygons() computes an sf polygon layer with one donut segment per non-zero location-category pair.

flow_lines() computes straight or curved origin-destination sf line geometries.

Example data

library(DonutMap)
library(ggplot2)

demo <- data.frame(
  place = rep(c("A", "B", "C"), each = 3),
  lon = rep(c(-71.35, -71.20, -71.05), each = 3),
  lat = rep(c(46.75, 46.82, 46.73), each = 3),
  category = rep(c("Walking", "Transit", "Car"), times = 3),
  value = c(10, 20, 5, 5, 15, 10, 12, 4, 9)
)

flows <- data.frame(
  from = c("A", "B"),
  to = c("B", "C"),
  trips = c(30, 10),
  flow_category = c("Transit", "Car")
)

mode_colours <- c(
  Walking = "#1b9e77",
  Transit = "#7570b3",
  Car = "#d95f02"
)

Static map

donut_map(
  demo,
  place,
  category,
  value,
  lon = lon,
  lat = lat,
  flows = flows,
  from = from,
  to = to,
  flow_value = trips,
  flow_group = flow_category,
  flow_colours = mode_colours,
  flow_curvature = 0.22,
  flow_arrow = TRUE,
  colours = mode_colours
)

Interactive map

donut_leaflet(
  demo,
  place,
  category,
  value,
  lon = lon,
  lat = lat,
  flows = flows,
  from = from,
  to = to,
  flow_value = trips,
  flow_group = flow_category,
  flow_colours = mode_colours,
  flow_curvature = 0.22,
  flow_arrow = TRUE,
  colours = mode_colours
)

Use flow_curvature = 0 for straight links, positive values for one bend direction, and negative values for the opposite direction. flow_arrow = TRUE adds directional arrows to the static and interactive trajectories. In donut_leaflet(), use flow_arrow_size to tune the arrowhead length in projected map units when the automatic size is not ideal. Use flow_group and flow_colours when the connections themselves should carry a categorical colour, for example destination municipality or flow type.

Examples and documentation

The pkgdown site includes a complete vignette with:

  • simulated Québec/eastern Canada example data;
  • a static ggplot2 donut map with coloured directional trajectories;
  • an interactive leaflet donut map with clickable coloured trajectories;
  • direct use of the sf geometry layer.

See vignette("donut-maps", package = "DonutMap") locally, or the online article:

https://aureliennicosiaulaval.github.io/DonutMap/articles/donut-maps.html.

Metadata

Version

0.1.0

License

Unknown

Platforms (79)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    wasip1
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasip1
  • wasm64-wasip1
  • x86_64-cygwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows