1.Search the internet for a polygon shapefile, 2.download it (this will be a ZIPPED folder), 3.extract the files into your GIS folder, 4.use the rgdal package to import the shapefile in R 5.use leaflet to make a map of the shape file.
dbf file link: https://github.com/hrbrmstr/ggcounty/tree/master/inst/counties
GIS Data link: https://www2.census.gov/geo/tiger/GENZ2016/shp/
library(foreign)
library(maptools)
## Warning: package 'maptools' was built under R version 3.4.4
## Loading required package: sp
## Warning: package 'sp' was built under R version 3.4.3
## Checking rgeos availability: FALSE
## Note: when rgeos is not available, polygon geometry computations in maptools depend on gpclib,
## which has a restricted licence. It is disabled by default;
## to enable gpclib, type gpclibPermit()
library(rgdal)
## Warning: package 'rgdal' was built under R version 3.4.4
## rgdal: version: 1.3-6, (SVN revision 773)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.2.3, released 2017/11/20
## Path to GDAL shared files: C:/Users/Chunqi/Documents/R/win-library/3.4/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/Chunqi/Documents/R/win-library/3.4/rgdal/proj
## Linking to sp version: 1.3-1
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.4.4
library(dplyr)
## Warning: package 'dplyr' was built under R version 3.4.3
##
## 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
PA_dat<-read.dbf("pennsylv.dbf")
PAdistricts<- readOGR(dsn = path.expand("/Users/Chunqi/Desktop/ANLY 512/Assignment 2/GIS data/cb_2016_42_unsd_500k"),layer="cb_2016_42_unsd_500k")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\Chunqi\Desktop\ANLY 512\Assignment 2\GIS Data\cb_2016_42_unsd_500k", layer: "cb_2016_42_unsd_500k"
## with 501 features
## It has 8 fields
## Integer64 fields read as strings: ALAND AWATER
PAcountry<- readOGR(dsn = path.expand("/Users/Chunqi/Desktop/ANLY 512/Assignment 2/GIS data/cb_2016_us_county_500k"),layer="cb_2016_us_county_500k")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\Chunqi\Desktop\ANLY 512\Assignment 2\GIS Data\cb_2016_us_county_500k", layer: "cb_2016_us_county_500k"
## with 3233 features
## It has 9 fields
## Integer64 fields read as strings: ALAND AWATER
Districts<-leaflet(PAdistricts) %>% addTiles() %>%
addPolygons(weight=.75,color="green",fillOpacity = .2)
Districts
icons <- awesomeIcons(icon = "blue",
iconColor = "black",
library = "glyphicon",
markerColor = "purple")
noofcardiac <- subset(PA_dat,cardiac == "Y")
PA_cardiac <- subset(noofcardiac, county == "Philadelphia")
leaflet(PA_cardiac, width = "100%") %>%
addTiles() %>%addProviderTiles(providers$Esri.WorldPhysical) %>%
addProviderTiles(providers$Esri.WorldPhysical,options = providerTileOptions(opacity = 0.50)) %>%
addProviderTiles(providers$Esri.WorldPhysical) %>%
addAwesomeMarkers(~x, ~y, popup = ~as.character(facility), icon = icons)