[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.

https://stat.ethz.ch/mailman/listinfo/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
>
>hb<-hexbin(DF$lon,DF$lat,xbins=80,IDs=TRUE)
>hb.avg<-hexTapply(hb,DF$Res,mean,na.rm=TRUE)
>hb.mx<-hexTapply(hb,DF$Res,max,na.rm=TRUE)
>hb.p80<-hexTapply(hb,DF$Res,quantile,prob=0.80,na.rm=TRUE)
>#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
>Base<-get_map(BBox,source='google')
>m_hx<-ggmap(Base,legend = "bottom",
>base_layer=ggplot(aes(x=x,y=y),data=hx_dat))
>#Map of means
>a<-0.55
>hc<-'grey60'
>
>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
>Mike
>
>Michael J. Bock, PhD | Senior Manager
>mbock at environcorp.com
>
>
>
>
>
>
>________________________________
>This message contains information that may be
>confidenti...{{dropped:8}}
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list