-1

Concept of ggmap seems clear to me:

  1. Use get_map to obtain a map at a certain location at a certain spatial zoom.

  2. Use ggmap() + ggplot() to combine map image with ggplot graphics.

The challenge at the moment lies in step 1 and, precisely, location parameter. Besides a longitude/latitude pair get_map accepts a character string, but no vector. It seems that there is no easy way to obtain a map that includes two or more states, or two or more cities.

Thus, to have a function that draws arbitrary number of (presumably adjacent) US states there is no shortcut but to go through elaborate process of geocoding each state and calculating optimal location and zoom (also not sure how).

topchef
  • 19,091
  • 9
  • 63
  • 102
  • A lot of us think it is your responsibility to provide code that loads the relevant packages, and then accesses the shapefiles to be used, and finally sets up a test case to test with. – IRTFM Nov 01 '13 at 19:00
  • I revised the question to avoid steering it towards policy/conventions/agreement discussions. I appreciate your opinion though. – topchef Nov 01 '13 at 19:53

1 Answers1

0

as you can find out here - http://journal.r-project.org/archive/2013-1/kahle-wickham.pdf - there is the way to put shapefile into ggmap.

All you need to do is:

# read data into R (for example - your states)
shapefile <- readShapeSpatial(’tr48_d00.shp’,proj4string = CRS("+proj=longlat +datum=WGS84"))
# convert to a data.frame using fortify function
data <- fortify(shapefile)
#and plot your data using qmap or ggmap
qmap(’texas’, zoom = 6, maptype = ’satellite’) + geom_polygon(aes(x = long, y = lat, group = group), data = data,colour = ’white’, fill = ’black’, alpha = .4, size = .3)
Jot eN
  • 6,120
  • 4
  • 40
  • 59
  • So I presume that concrete shapefile has to include those states (or cities, or whichever multiple geo artifacts I deal with), right? – topchef Nov 01 '13 at 19:31
  • yes, you're right;) Of course, you also need to change qmap code a little bit - from 'texas' to your area, change zoom, etc. – Jot eN Nov 01 '13 at 19:39
  • I guess I need to revise my question since the whole point is find approach to parameterized list of artifacts (maybe restrict them to states or cities within US). – topchef Nov 01 '13 at 19:44
  • right now I am taking approach of `geocode`ing each artifact from the list and then taking means of lat/lon, after that manually adjusting zoom. Basically I am looking for solution in that direction. – topchef Nov 01 '13 at 19:59