Question

I just started play with RgoogleMaps http://cran.r-project.org/web/packages/RgoogleMaps/RgoogleMaps.pdf and it seems really cool, but it seems like there is a limitation in the GetMaps() path option. It looks like (and I might be wrong) a url is sent to the google static maps api and a png file (or something) is download, so the url limit limits the size of the path you can have in your "map.png". But I'm wondering if it would be easy to edit the png afterward creation or in an intermediate processing step in order to have long paths? Does anybody know how to do this in r? The package seems to give a function that maps XY coordinates to png raster. And if you haven't noticed I'm far from an expert in png files, so if there is something simple that I'm missing please be gental.

Was it helpful?

Solution

Update opts is deprecated; use theme instead.

If you're prepared to work in ggplot2, the ggmap package makes the adding of layers to a map easy. The get_map() function below fetches a satellite googlemap of the National Research Institute in Port Moresby, PNG. The ggmap() function draws the map, then adds a text annotation, a line segment annotation, and a title. But other geoms can be added just as they would be to a regular ggplot graph. The gglocator() function works in a similar way to locator() in base plots. lon and lat are the coordinates for the centre of the map, but the location vector can be given the boundaries of the map. I played with zoom to get the right resolution.

library(ggplot2)
library(ggmap)
library(grid)

nri = get_map(location = c(lon = 147.165, lat = -9.410), zoom = 18, maptype = 'satellite')

(NRImap = ggmap(nri, extent = "device") + 
  annotate('segment', x = 147.1656, xend = 147.1649, y = -9.41025, yend = -9.4096,
    colour = 'white', arrow = arrow(length = unit(0.25,"cm")), size = 1) +
  annotate('text', x = 147.1656, y = -9.41031, label = 'Conference Centre',
    colour = 'white', size = 6) +
  theme(plot.margin = unit(c(1.5, 0, 0, 0), "lines")) + 
  ggtitle                       ("National Research Institute") +
  theme(plot.title = element_text(colour = "Blue", vjust = 2, size = 20)))

# gglocator()

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top