Using ggmap map of the world
Asked Answered
O

1

8

I am trying to obtain a simple raster map of the entire world, using the ggmap package / get_map functionality (see code below) in combination with ggplot2. The zoom levels only go towards "3", and do not allow further zooming out

it seems impossible to get a world map (as documented in the ggmap description: ("maps of the whole world currently not supported"). Perhaps due to a lack of understanding why this is not possible / supported, is there a work-around / alternative solution to have a world map view?

EDIT / UPDATE on QUESTION: I have tried to use the world-map as suggested - but for some reason i don't understand why it doesn't allow me to plot points in the graph (which was the original aim, and does work in ggmap)- feel that i am doing something stupid / making basic mistake. I get error message "Error in eval(expr, envir, enclos) : object 'group' not found"

EDIT- unfortunately i get an error message using OpenStreetMap (java error. working on fixing this - but non OpenStreetMap solutions would be great...)

To summarize - the ggmap approach works with geom_point, but i cannot get a whole world map. the worldmap approach should work, but for some reason cannot get points to plot.....

NEW CODE per below:

ggmap approach:

library(ggmap)
library(ggplot2)

reclat=c(50,20,30,40)
reclong=c(30,40,30,50)         
points=as.data.frame(cbind(reclat,reclong))

al1 = get_map(location = 'Europe', zoom = 3, color="bw",maptype = "satellite")
map = ggmap(al1)
map 

#this works
map+geom_point(data=points, aes(x=reclong, y=reclat, colour="red"))

worldmap approach:

world <- map_data("world")
worldmap <- ggplot(world, aes(x=long, y=lat, group=group)) +
  geom_path() +
  scale_y_continuous(breaks=(-2:2) * 30) +
  scale_x_continuous(breaks=(-4:4) * 45)

#this works
worldmap + geom_point(aes(50, 30, colour="red"))

#this doesnt work
worldmap + geom_point(data=points, aes(x=reclong, y=reclat, colour="red"))
Oscillogram answered 23/5, 2013 at 11:59 Comment(2)
check this out: #16029159Mandamus
its Dec. 2016. Now the minimum zoom factor is zoom=2, this gives you the eastern/western hemisphere of the globe.Gerge
D
4

You can try the OpenStreetMap package, which has access to many different map servers, though not GoogleMaps.

library(OpenStreetMap)
library(ggplot2)
map <- openmap(c(70,-179),
               c(-70,179),zoom=1)
map <- openproj(map)


reclat <- c(50,20,30,40)
reclong <- c(30,40,30,50)         
autoplot(map) + geom_point(aes(x=reclong,y=reclat))
Dominions answered 23/5, 2013 at 15:49 Comment(2)
ggmap also implements OpenStreetMap functionality, so why can't this be done in ggmap alone? Also, using your example code, the map's resolution is pretty bad, I assume there's a way to improve that?Timeworn
You can make zoom larger for higher resolution. The package will stitch together the relevant tiles. but there are two additional issues here. The first is that the text is designed to be viewed in mercator coordinates, not long-lat. This is the reason why OpenStreetMap doesn't transform to long-lat by default. The second is the way that ggplot2 (i.e. grid) renders rasters. For some reason it does not seem to as good as base. See the difference between plot(map) and autoplot(map).Dominions

© 2022 - 2024 — McMap. All rights reserved.