Skip to content

Instantly share code, notes, and snippets.

@geotheory
Created July 31, 2015 13:07
Show Gist options
  • Save geotheory/2b921aff20b5579793ec to your computer and use it in GitHub Desktop.
Save geotheory/2b921aff20b5579793ec to your computer and use it in GitHub Desktop.
Get aspect ratio for a small-area lat-long dataset to approximate Mercator projection
# ref: http://stackoverflow.com/questions/31745894/get-aspect-ratio-for-lat-long-plots/31746542#31746542
# requires ggplot2
map_aspect = function(x, y) {
x.center <- sum(range(x)) / 2
y.center <- sum(range(y)) / 2
x.dist <- ggplot2:::dist_central_angle(x.center + c(-0.5, 0.5), rep(y.center, 2))
y.dist <- ggplot2:::dist_central_angle(rep(x.center, 2), y.center + c(-0.5, 0.5))
y.dist / x.dist
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment