Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ggmap map of the world

Tags:

r

ggplot2

ggmap

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"))
like image 629
user1885116 Avatar asked May 23 '13 11:05

user1885116


People also ask

How do I use Ggmap?

Make a Google Map Specify a place, or center = c(longitude,latitude) coordinates. Zoom size = 10 is default for city level zoom, higher numbers are zoomed in more. Choose a map type = c(“terrain”, “satellite”, “roadmap”, “hybrid”) and color = c(“color”, “bw”) Renders a 1280x1280 pixel map (ggmap/raster object).


1 Answers

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))
like image 74
Ian Fellows Avatar answered Oct 14 '22 23:10

Ian Fellows