Misalignment of ggmap and ggplot geom_points?

Showing 1-9 of 9 messages
Misalignment of ggmap and ggplot geom_points? JBlack 3/8/12 2:18 PM
Hi,

Can anyone shed light on what I'm doing wrong here? I would expect the
data points and the google raster map to align better that what I'm
seeing.

# 1st 2 points at fixed latitudes (46, 43),
# 2nd 2 points on known points of land (Cape George, Sable Island)
# while the fixed latitudes line up with the axis labels, the points
of land
# suggest that the Google map is not aligned properly

lon = c(-67.2, -67.2,-61.95640829749075, -60.1334953);
lat = c(46, 43, 45.83594917946984, 43.9634132);
size = c(100,100,100,100);
myData = data.frame(lon,lat,size)

require(ggmap)
lonlatC <- c(lon=mean(myData$lon), lat=mean(myData$lat))
osm <- ggmap(center=lonlatC, source = "google",
zoom=6,maptype="satellite")
ggmapplot(osm, maprange = FALSE, expand = FALSE,
          base_layer=ggplot(myData, aes(x=lon, y=lat))) +
            geom_point(aes(size=size))

Thanks
Jerry
Re: Misalignment of ggmap and ggplot geom_points? JBlack 3/8/12 5:04 PM
The attached pdf shows the effect...

Thanks
Jerry
Re: Misalignment of ggmap and ggplot geom_points? AJSmit 3/8/12 10:23 PM
Hi,


Paul Hiemstra suggests setting an often to the Google raster to align its position with that of the points. It works as an interim solution, but in the long run I think it will remain unsatisfactory as it does not get to the heart of the problem. Paul suggests the Google Maps bounding box definition is wrong somehow, and I find that specifying an offset indeed corrects it.

I found that setting MINIMUMSIZE = TRUE in the GetMap.bbox() function brings things into better alignment, but it is not perfect. I have not yet had time to play around some more.

AJ
unk...@googlegroups.com 3/8/12 10:10 PM <This message has been deleted.>
Re: Misalignment of ggmap and ggplot geom_points? David Kahle 3/9/12 7:28 AM
There is actually a bigger problem here which can't be solved by simply changing the bounding box as suggested.

The problem is that at very low zooms (very low scales, big extents), the plotting is unreliable as evidenced by the code below (you will need the dev version for the code to work) :

library(devtools)
dev_mode()
install_github('ggmap', 'dkahle')
library(ggmap)


gc <- geocode('the white house')

qmap('the white house', zoom = 20, maptype = 'satellite') +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 18, maptype = 'satellite') +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 16, maptype = 'satellite') +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 14, maptype = 'satellite') +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

  

qmap('the white house', zoom = 10) +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

  

qmap('the white house', zoom = 8) +
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

  

qmap('the white house', zoom = 7) + # first observed effect (very slight)
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')  

qmap('the white house', zoom = 6) + # first real observed effect
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

  

qmap('the white house', zoom = 5) + # effect more pronounced
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

  

qmap('the white house', zoom = 4) + # woe!
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 3) + # white house in canada?
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 2) + # white house approaching santa's workshop
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')

qmap('the white house', zoom = 2, source = 'osm') + # osm has effect, too
  geom_point(aes(x = lon, y = lat), data = gc, colour = 'red')


So for the time being be very cautious with zooms <= 7.  I'll work to resolve the issue as soon as possible.

Thanks
david.


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Re: Misalignment of ggmap and ggplot geom_points? David Kahle 3/9/12 4:58 PM
Hi Jerry, AJ -

This problem is now solved in the development version -

library(devtools)
dev_mode()
install_github('ggmap', 'dkahle')
library(ggmap)

lon = c(-67.2, -67.2,-61.95640829749075, -60.1334953);
lat = c(46, 43, 45.83594917946984, 43.9634132);
size = c(100,100,100,100);
myData = data.frame(lon,lat,size)

require(ggmap)
lonlatC <- c(lon=mean(myData$lon), lat=mean(myData$lat))
osm <- ggmap(center=lonlatC, source = "google",
zoom=6,maptype="satellite")
ggmapplot(osm, maprange = FALSE, expand = FALSE,
         base_layer=ggplot(myData, aes(x=lon, y=lat))) +
           geom_point(aes(size=size))

Cheers
dk.

On Mar 9, 2012, at 12:23 AM, AJSmit wrote:

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Re: Misalignment of ggmap and ggplot geom_points? David Kahle 3/9/12 5:11 PM
BTW, you probably want to change some of the parameters...  Here's how it can be done.

lon <- c(-67.2, -67.2,-61.95640829749075, -60.1334953)
lat <- c(46, 43, 45.83594917946984, 43.9634132)
size <- 1:4
myData <- data.frame(lon, lat)

require(ggmap)
lonlatC <- c(lon=mean(myData$lon), lat=mean(myData$lat))
osm <- ggmap(
  center = lonlatC, source = "google", 
  zoom = 7, maptype = "satellite"
)
ggmapplot(osm, maprange = TRUE, expand = FALSE, 
  base_layer = ggplot(myData, aes(x=lon, y=lat))
) + geom_point(aes(size=size), colour = 'red')

dk.



--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
<ggmap_point_mismatch.pdf>

Re: Misalignment of ggmap and ggplot geom_points? JBlack 3/11/12 3:14 PM
Thank you. works well!
Re: Misalignment of ggmap and ggplot geom_points? AJSmit 3/12/12 5:32 AM
Dear David,

That's great, it works perfectly!

Much appreciated,
AJ