Question

I would like to plot cities of the world, over a map of the world using ggmap.

I have the cities of the world plotting fine. But the backdrop of a world map is a lot more difficult than I thought.

My code is as follows:

map1 <- openmap(c(70,-179),
              c(-70,179),zoom=1)
map1 <- openproj(map)


reclat <- c(50,20,30,40)
reclong <- c(30,40,30,50)        
autoplot(map1) + geom_point(aes(x=reclong,y=reclat))
qmplot(long,lat,data=world.cities,colour=I('red'), size = I(3), darken = .3)

This may sound vague, but I have absolutely no idea how to create some sort of 'background' that is actually a world map!

I have been reading the documentation and looking at examples, but I can't find a solution.

Any advice is greatly appreciated.

Here is a map that the code produces:

Was it helpful?

Solution

With rworldmap and base graphics:

library(rworldmap)
plot(getMap())
points(world.cities$long,world.cities$lat,col="red")

OTHER TIPS

The package 'maps' does it for you

library(maps)
map()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top