[R-sig-Geo] Positing a coord_proj for ggplot2

boB Rudis bob at rudis.net
Fri Jul 24 15:07:44 CEST 2015

Hey folks

Having finally gotten tired of performing coordinate conversions to
Winkel-Tripel (and other) projections prior to passing map data to
ggplot2 (coord_map projection support is limited to what mapproject
supports and that's pretty scant) I was toying with a coord_proj
coordinate system for ggplot2 the other day and came up with this:
https://gist.github.com/hrbrmstr/363e33f74e2972c93ca7 (visual:

coord_proj uses proj4::project, so it supports any proj4string.

This won't be in ggplot2 right now as Hadley is updating/refactoring
the package and "coords" are going to work a bit differently. Plus
this adds a dependency I'm not sure he wants to add to it. You can
stick it in your own, local copy of ggplot2 and re-collate and rebuild
to use it.

proj4::project (and even spTransform, to a certain degree - no pun
intended) are unhappy dealing with lat/lon values outside the -90/90 :
-180:180 range and even have some issues with points right at the
extremes, so I did the following in the linked code:

df$x <- ifelse(df$x <= -180, -179.999999999, df$x)
df$x <- ifelse(df$x >= 180, 179.999999999, df$x)
df$y <- ifelse(df$y <= -90, -89.999999999, df$y)
df$y <- ifelse(df$y >= 90, 89.999999999, df$y)

It was a quick hack to just get coord_proj up and running and I know
it's a horrible one, but I'm looking for guidance/feedback/etc on what
I _should_ do here since I will be maintaining some version of this
moving forward (it's just too convenient for me not to and the new
"coords" may be as extensible as the forthcoming change to "geoms", so
this could be in a package all itself or added to another R geo



More information about the R-sig-Geo mailing list