1

I am trying to map some data in R with the mercator map as a background.

Here is what is I am using, the data points come out fine, but I am not getting the map.

qplot(nt_phi_lambda$longitude, xlab='Longitude', 
    nt_phi_lambda$latitude, ylab='Latitude', 
    data=nt_phi_lambda, main='Global Indsutry Break-down', 
    colour=industry, projection='mercator()', parameters=c(0,0,0))
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
RomainD
  • 97
  • 2
  • 7
  • 1
    Without a data set it's much more difficult to assist you as your problem isn't reproducible. I also would suggest that for problems of increasing complexity you move to use `ggplot` rather than `qplot` – Tyler Rinker May 16 '12 at 15:48
  • Background? Are you expecting qplot to magically know your data is world data, to know the coordinates of world countries, and to draw all that for you? You are probably going to need a geom_map somewhere in there... http://stackoverflow.com/questions/9558040/ggplot-map-with-l – Spacedman May 16 '12 at 22:26

1 Answers1

1

You need a data.frame with the coordinates of the country boundaries. Just setting projection = 'mercator() does not add a map in mercator projection. See a recent question of mine for an example of how to plot a world map. An example in a few lines of code:

require(maps)
world_map = data.frame(map(plot=FALSE)[c("x","y")])
ggplot(aes(x = x, y = y), data = world_map) + geom_path()

See also the documentation of coord_map.

Community
  • 1
  • 1
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149