library (rgdal)
## Loading required package: sp
## rgdal: version: 0.9-1, (SVN revision 518)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.1, released 2014/09/24
## Path to GDAL shared files: /usr/local/Cellar/gdal/1.11.1/share/gdal
## Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
## Path to PROJ.4 shared files: (autodetected)
library(sp)
library (ggplot2)
library (ggmap)
library(historydata)
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:stats':
##
## filter, lag
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
data (early_colleges)
head (early_colleges)
## Source: local data frame [6 x 6]
##
## college original_name city state
## 1 Harvard NA Cambridge MA
## 2 William and Mary NA Williamsburg VA
## 3 Yale NA New Haven CT
## 4 Pennsylvania, Univ. of NA Philadelphia PA
## 5 Princeton College of New Jersey Princeton NJ
## 6 Columbia King's College New York NY
## Variables not shown: established (int), sponsorship (chr)
early_colleges<- early_colleges%>%
mutate(location=paste (city, state))
location_geocoded <- geocode(early_colleges$location)
early_colleges_geocoded <- cbind(early_colleges, location_geocoded)
map1850<- readOGR ("nhgis-shp" , "state_1850")
## OGR data source with driver: ESRI Shapefile
## Source: "nhgis-shp", layer: "state_1850"
## with 37 features and 7 fields
## Feature type: wkbPolygon with 2 dimensions
fort<- fortify (map1850)
## Regions defined for each Polygons
ggplot () + geom_map(data=fort, map=fort, aes(x=long, y=lat, group=group, map_id=id), color="black", fill="white") +geom_point(data=early_colleges_geocoded, aes (x=lon, y=lat), color="red") + coord_map()

ggplot () + geom_map(data=fort, map=fort, aes(x=long, y=lat, group=group, map_id=id), color="black", fill="white") +geom_point(data=early_colleges_geocoded, aes (x=lon, y=lat, color=factor(established)) ) + coord_map()
