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"))
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))