MyNixOS website logo
Description

Create Draggable Plots from Projected Geometry.

Creates interactive draggable plots from grouped projected 'sf' geometry. The primary deliverable is a browser-based 'D3' helper where regions and labels can be moved freely; users drag, then copy or download the resulting offset tables. Labels can be derived automatically with make_region_labels(), supplied directly with as_drag_labels(), and their moved positions saved and restored with read_label_state() and apply_label_state(). Hierarchical spatial datasets are supported via hierarchy detection, upload profiling, make_hierarchy_key(), and inherit_layout(), which recommend parent-child groupings and propagate parent-level drag offsets to finer child groupings. Automatic starting layouts are provided by suggest_offsets() using radial, grid, or directional algorithms. Spatial file diagnostics are available through dragmapr_diagnostics(). When a reproducible static image is also needed, render_dragged_map() reconstructs the layout as a 'ggplot2' plot from the source geometry plus the exported offset tables. Project bundles can be written with write_dragmapr_project() and rendered with render_dragmapr_project(). The interactive layer is built on the 'D3' library: Bostock, Ogievetsky and Heer (2011) <doi:10.1109/TVCG.2011.185>. Spatial data handling uses the 'sf' package: Pebesma (2018) <doi:10.32614/RJ-2018-009>.

dragmapr

dragmapr hex logo

R-CMD-check

dragmapr lets you drag map regions into any layout you want, then save that layout as a reproducible image. Open a draggable map in your browser, move regions and labels around until things look right, download two small CSV files, and turn them into a publication-ready ggplot2 map.

Watch a short walkthrough in the dragmap demo vignette, or see the HHS placeholder shapes demo for a complete Spatial Studio workflow.

Install

# install.packages("pak")
pak::pak("PrigasG/dragmapr")

Quick Start

library(dragmapr)

# Step 1: open the interactive map in your browser and drag things around
drag_map_prototype(my_sf, region_col = "region", open = TRUE)

# Step 2: after downloading the offset CSVs, render a static image
render_dragged_map(
  my_sf,
  region_col    = "region",
  region_offsets = "drag_region_offsets.csv",
  label_offsets  = "drag_label_offsets.csv",
  file = "my-map.png"
)

If your data is in longitude/latitude, run prepare_dragmapr_sf() first:

my_sf <- prepare_dragmapr_sf(my_sf)

How It Works

  1. Start with a polygon sf object and pick a column that groups your regions.
  2. Call drag_map_prototype() to open a browser page — drag regions and labels wherever you like.
  3. Click Copy or Download in the side panel to save the offset CSVs.
  4. Call render_dragged_map() with those CSVs to get a static ggplot2 image anytime, without re-running a browser session.

If you used Spatial Studio, you can skip steps 3–4 and call render_dragmapr_project() with the project ZIP instead:

render_dragmapr_project(
  "dragmapr-project.zip",
  file = "final-map.png",
  width = 10, height = 8, dpi = 300
)

Labels and Connectors

Labels are optional. You can show one label per region, supply your own label table, or turn labels off entirely.

# One label per region (default)
drag_map_prototype(my_sf, "region")

# Text-only labels, no marker
drag_map_prototype(my_sf, "region", label_marker = FALSE)

# Circle markers instead of rectangles
drag_map_prototype(my_sf, "region", label_marker_shape = "circle")

For longer notes or callout boxes, use as_drag_annotations():

notes <- as_drag_annotations(data.frame(
  label_id = "north-note",
  region   = "North",
  label    = "A note about this region",
  x = 50000, y = 150000
), connector = TRUE, connector_type = "curve")

render_dragged_map(my_sf, "region",
  region_offsets = "drag_region_offsets.csv",
  labels         = notes,
  label_offsets  = "drag_label_offsets.csv",
  connector_endpoint = "arrow",
  file = "annotated-map.png"
)

Connector styles: "straight", "elbow", "curve", "squiggle". Endpoints: "none" or "arrow".

RStudio Addin

After installing, go to Addins > Launch dragmapr in RStudio. Pick your sf object, choose columns and styling, drag the layout, then click Done. The addin saves region_offsets and label_offsets to .GlobalEnv so you can pass them straight to render_dragged_map().

# Load your sf object first, then launch the addin
regions <- prepare_dragmapr_sf(sf::st_read("regions.shp", quiet = TRUE))
dragmapr_addin()

render_dragged_map(regions, region_col = "name",
  region_offsets = region_offsets,
  label_offsets  = label_offsets,
  file = "map.png"
)

Built-in Examples

Run any example to see the package in action without needing your own data:

  • basic_draggable_map.R — four simple map regions
  • explodemap_hhs_labels.R — HHS-style exploded layout with colors and offsets
  • label_nudging.R — nudge labels independently after moving regions
  • shiny_draggable_export.R — Shiny app with live preview and PNG export
  • shiny_spatial_studio.R — full Spatial Studio: upload files, switch groupings, drag, export
  • branch-bloom-tester.R — test parent/child bloom animations in isolation
# Run all examples in a temp folder
source(system.file("examples", "smoke_examples.R", package = "dragmapr"))

Need an export format not available in Spatial Studio? Download the GeoJSON or GeoPackage and open it in Mapshaper to convert.

Vignettes

  • Getting started with dragmapr
  • Dragmap demo
  • Labels and static output
  • Shiny workflows
  • Example gallery
  • HHS placeholder shapes demo

Known Limitations

  • Designed for polygon and multipolygon data. Point and line workflows may work in parts but are not the main supported path.
  • Offsets are stored in projected coordinate units. Use prepare_dragmapr_sf() to convert longitude/latitude data before dragging.
  • Dragged geometry is for display and communication, not geographic analysis.
  • Very large datasets can be slow in the browser. Simplify or group geometry first when working at large scale.
Metadata

Version

0.2.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