1

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:

tumultous_rooster
  • 12,150
  • 32
  • 92
  • 149
  • 1
    Have you looked at the maps package? Have a look at: http://stackoverflow.com/questions/11201997/world-map-with-ggmap – Tyler Rinker Feb 10 '14 at 05:18
  • I attempted a bit of cannibalization of that code at one point, but it didn't seem to work with my data too well...didn't seem to be a straightforward way to switcheroo my long and lat data. But I will keep trying.. – tumultous_rooster Feb 10 '14 at 05:22
  • Strange that this is so difficult. Do you have to use `ggmap`? Otherwise you could just do `library(maps); map();` and away you go. Your intended plot doesn't sound like it needs anything too advanced. – thelatemail Feb 10 '14 at 05:26
  • 1
    ?get_map says "maps of the whole world currently not supported" – Joe Feb 10 '14 at 05:32
  • @thelatemail `maps` still has USSR on its world map; `rworldmap` is way more recent. – mbq Feb 10 '14 at 08:37
  • so I'm realizing that maps is outdated and ggplot has no world map? – tumultous_rooster Feb 10 '14 at 09:11

2 Answers2

3

With rworldmap and base graphics:

library(rworldmap)
plot(getMap())
points(world.cities$long,world.cities$lat,col="red")
mbq
  • 18,510
  • 6
  • 49
  • 72
0

The package 'maps' does it for you

library(maps)
map()
RockScience
  • 17,932
  • 26
  • 89
  • 125