[R] ggmap, hexbin and length distortion in Lat/long

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Fri May 24 17:03:00 CEST 2013

I would suggest asking this on R-sig-geo.

Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
Sent from my phone. Please excuse my brevity.

Mike Bock <mbock at environcorp.com> wrote:

>I am working with spatial data in ggmap, generally with great success.
>I have a huge data set with the coordinates in NAD 83 UTM Zone 11
>(meters).  To map the data the coordinates were converted to Lat Long
>in GIS prior to use in R and ggmap/ggplot. I am using hexagonal binning
>to aggregate the data :
>#create bins and calculate stats
>#create df for ggplot
>hx_dat <- data.frame(hcell2xy(hb), count = hb at count,
>    xo = hb at xcm, yo = hb at ycm, Mean=hb.avg,Max=hb.mx,
>    p80=hb.p80)
>#Base Map
>#BBox is the bounding box
>m_hx<-ggmap(Base,legend = "bottom",
>#Map of means
>m_hx+geom_hex(aes(x = x, y = y, fill = Mean),
>  color = hc, ,alpha=a,stat = "identity") +
>  scale_fill_gradientn("Mean",colours=rev(rainbow(4)),trans='sqrt')
>...and so on for other stats
>I can also run statistical analyses on hx_dat.
>By creating hexbins based on lat/long it seems there will be distortion
>due to the differences in length of a degree at different locations on
>the earth's surface. What is the most efficient way to eliminate this
>distortion? Should I run hexbin in NAD83 and convert the x/y
>coordinates to Lat Long? Can I get ggmap to convert the baselayer to
>NAD84 and just do everything in NAD(my preferred option)?
>I have tried converting Lat Long to NAD84 and back but the coordinates
>are coming up in the eastern Pacific and not in California, so I am
>missing something and I am not sure that is the best way to solve the
>problem anyway. Thanks in advance, any help is greatly appreciated
>Michael J. Bock, PhD | Senior Manager
>mbock at environcorp.com
>This message contains information that may be
>R-help at r-project.org mailing list
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list