Skip to content

Instantly share code, notes, and snippets.

View bleutner's full-sized avatar

Benjamin Leutner bleutner

  • The Landbanking Group
  • Germany
View GitHub Profile
@bleutner
bleutner / ggScalebar.R
Last active February 23, 2019 04:10
Scalebar for ggplot2 spatial maps
##
## Example for an entirely non-smart scalebar, which can be added to a ggplot2 object
## Author: Benjamin Leutner (@bleutner)
##
ggScalebar <- function(origin, ## raster object or vector in the form of c(xmin, ymin)
breaks = seq(0, 10000, 1000), ## breaks for the scale bar
yoff = 1000, xoff = 1000, ## position offset from origin in x and y direction (in map units)
sdist = 1000, ## length of major ticks (in map units)
tdist = 1000, ## distance labels to ticks (in map units)
size = 1, ## linewidth of scalebar