Get aspect ratio for lengthy graphs
I know R has various ways to display projection maps correctly. But just for a quick "good enough" result using basic functions, is there a function to calculate the aspect ratio for a given latitude, assuming that the typical R arguments asp
will approximate the correct plot? those. something that is equivalent to ggplot2 coord_quickmap . Grateful for any suggestions.
source to share
If what it suggests coord_quickmap
is close enough for you, you can do:
library(ggplot2)
library(maps)
library(mapdata)
# shamelessly stolen from coord_quickmap
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
}
What ggplot
will do:
ggplot(data.frame(state.center)) + geom_point(aes(x=x, y=y)) + coord_quickmap()
The same thing, now, in the database:
plot(state.center$x, state.center$y,
asp=map_aspect(state.center$x, state.center$y))
Remember, however, that coord_quickmap
(and therefore the calculated ratio from it) was calculated for small areas. I am posting some resources for the ability to display map projections here: here , which will work great with spTransform
and base).
source to share