Tagged with gps …

I just finished my submission for Look What I Made Weekend 9. Look What I Made Weekend (LWIMW) is a chance for people to create something over the course of 48 hours. The concept is based on Ludum Dare and other game jams, but for LWIMW you don't have to make a game. Instead, you are free to pursue any creative endeavor and show off your results at the end.

Let's learn how to use Shapefiles in R. This will allow us to map data for complicated areas or jurisdictions like zipcodes or school districts. For the United States, many shapefiles are available from the [Census Bureau](http://www.census.gov/geo/www/tiger/tgrshp2010/tgrshp2010.html. Our example will map U.S. national parks.

Next, we can use the function SMA from the package TTR to calculate a moving average of the altitude or elevation data, if we want to smooth out the curve. We can define a constant for the number of data points we want to average to create each moving average value.

If you don't want to convert meters to feet, a metric version of the code is available in the gist (callanMetric.R).

There are many different maps you can use for a background map for your gps or other latitude/longitude data (i.e. any time you're using geom_path, geom_segment, or geom_point.)

get_map

Helpfully, there's just one function that will allow you to query Google Maps, OpenStreetMap, Stamen maps, or CloudMade maps: get_map in the ggmap package. You could also use either get_googlemap, get_openstreetmap, get_stamenmap, or get_cloudmademap, but instead you can just use get_map for the same functionality as all of those combined. This makes it easy to try out different basemaps for your data.

You need to supply get_map with your location data and the color, source, maptype, and zoom of the base map.

source = "google", maptype = "terrain"

source = "google", maptype = "satellite"

Max zoom: 20

source = "google", maptype = "roadmap"

source = "google", maptype = "hybrid"

Hybrid combines roadmap and satellite.

Max zoom: 14

source = "osm"

get_map option source = "osm" (or using get_openstreetmap) downloads a map from OpenStreetMap. These maps are Creative Commons licensed, specifically Attribution-ShareAlike 2.0 (CC-BY-SA). This means you are free to use the maps for commercial purposes, as long as you release your final product under the same Creative Commons license. OpenStreetMap has no maptype options.

source = "osm" (no maptype needed)

Max zoom: 20

source = "stamen"

get_map option source = "stamen" (or using get_stamenmap) downloads a map from Stamen Maps. The map tiles are by Stamen Design, licensed under CC BY 3.0. The data for Stamen Maps is by OpenStreetMap, licensed under CC BY SA. Stamen has three different maptype options: terrain, watercolor, and toner.

source = "stamen", maptype = "terrain"

Max zoom: 18

source = "stamen", maptype = "watercolor"

Max zoom: 18

source = "stamen", maptype = "toner"

Max zoom: 18

source = "cloudmade"

N.B. As of March 2014, CloudMade no longer provides this API service.

CloudMade styles build on top of OpenStreetMap data. Thousands of CloudMade styles are available. You can browse them on the CloudMade site. You can also make your own styles.