R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

library(foreign)
library(ggplot2)
library(ggthemes)
library(ggmap)
library(raster)
## Loading required package: sp
library(rgdal)
## rgdal: version: 1.2-16, (SVN revision 701)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 2.2.0, released 2017/04/28
##  Path to GDAL shared files: C:/Users/Vivek/Documents/R/win-library/3.3/rgdal/gdal
##  GDAL binary built with GEOS: TRUE 
##  Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493]
##  Path to PROJ.4 shared files: C:/Users/Vivek/Documents/R/win-library/3.3/rgdal/proj
##  Linking to sp version: 1.2-6

Including Plots

You can also embed plots, for example:

df= read.dbf("pennsylv.dbf")
# pennsylv.shp file from moodle wasn't readable in R so I downloaded the file from the link provided in Q&A forum in moodle. 

# Map1 showing all the hospitals in Pennsylvania
Map1 = ggmap(get_map("Pennsylvania", zoom = 7), extent = "device", legend = "topleft") 
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Pennsylvania&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Pennsylvania&sensor=false
Map1 + geom_point(data = df, aes(x = LONGITUDE, y = LATITUDE), color = "red", darken = 0.1) +
  labs(x = "", y ="", title = "Hospitals in Pennsylvania Region") + theme_map()

# Map2 showing all the hospitals in Philadelphia
Map2= ggmap(get_map("Philadelphia", zoom = 7), extent = "device", legend = "topleft") 
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Philadelphia&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Philadelphia&sensor=false
Map2 + geom_point(data = df, aes(x = LONGITUDE, y = LATITUDE), color = "red", darken = 0.1) +
  labs(x = "", y ="", title = "Hospitals in Philly Region") + theme_map()

# Map3 showing all the hospitals in Pittsburgh
Map3= ggmap(get_map("Pittsburgh", zoom = 7), extent = "device", legend = "topleft") 
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Pittsburgh&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Pittsburgh&sensor=false
Map3 + geom_point(data = df, aes(x = LONGITUDE, y = LATITUDE), color = "red", darken = 0.1) +
  labs(x = "", y ="", title = "Hospitals in Pittsburgh Region") + theme_map()

# Map 4 showing all the hospitals in Harrisburg
Map4= ggmap(get_map("Harrisburg", zoom = 7), extent = "device", legend = "topleft") 
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Harrisburg&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Harrisburg&sensor=false
Map4 + geom_point(data = df, aes(x = LONGITUDE, y = LATITUDE), color = "red", darken = 0.1) +
  labs(x = "", y ="", title = "Hospitals in Harrisburg Region") + theme_map()

# Map 5 showing all the hospitals in Erie
Map5= ggmap(get_map("Erie", zoom = 7), extent = "device", legend = "topleft") 
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Erie&zoom=7&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Erie&sensor=false
Map5 + geom_point(data = df, aes(x = LONGITUDE, y = LATITUDE), color = "red", darken = 0.1) +
  labs(x = "", y ="", title = "Hospitals in Erie Region") + theme_map()

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.