Objectives

Using the spatial visualization techniques, we explore the data set on Pennsylvania hospitals (http://www.arcgis.com/). We create a series of 5 maps that highlight spatial differences in hospital service coverage for the state of PA.

Load the data and review data structure

To import the data we used the foreign package.

HospitalsPA <- read.dbf("C:/Harrisburg University Classes/Sem 2 - Fall 2017/ANLY-512 Data Visualisation/Assignments/Problem Set 5/pennsylv/pennsylv.dbf")

PA_Hospitals <- as.data.frame(HospitalsPA)
# View(PA_Hospitals)
# PA state terrain map
PA_state1 <- get_map(location = "pennsylvania state", zoom = 6,
                    maptype = "terrain")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=pennsylvania+state&zoom=6&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=pennsylvania%20state&sensor=false
PA_terrain <- ggmap(PA_state1, extent = "device")

# Philadelphia city terrain map
Philly1 <- get_map(location = "Philadelphia", zoom = 12,
                    maptype = "terrain")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Philadelphia&zoom=12&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
Philly_terrain <- ggmap(Philly1, extent = "device")

# Philadelphia city tonerlite map
Philly2 <- get_map(location = "Philadelphia", zoom = 11,
                    maptype = "toner-lite")
## maptype = "toner-lite" is only available with source = "stamen".
## resetting to source = "stamen"...
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Philadelphia&zoom=11&size=640x640&scale=2&maptype=terrain&sensor=false
## Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Philadelphia&sensor=false
## Map from URL : http://tile.stamen.com/toner-lite/11/595/774.png
## Map from URL : http://tile.stamen.com/toner-lite/11/596/774.png
## Map from URL : http://tile.stamen.com/toner-lite/11/597/774.png
## Map from URL : http://tile.stamen.com/toner-lite/11/595/775.png
## Map from URL : http://tile.stamen.com/toner-lite/11/596/775.png
## Map from URL : http://tile.stamen.com/toner-lite/11/597/775.png
## Map from URL : http://tile.stamen.com/toner-lite/11/595/776.png
## Map from URL : http://tile.stamen.com/toner-lite/11/596/776.png
## Map from URL : http://tile.stamen.com/toner-lite/11/597/776.png
Philly_tonerlite <- ggmap(Philly2, extent = "device")
# All Hospitals in PA Map
PA_terrain + 
  geom_point(aes(x = x, y = y),
             data = PA_Hospitals, 
             col="red", alpha = 0.4)

# Hospitals with Air Ambulance facilities
Air_Ambulance <- PA_Hospitals %>%
  filter(air_amb == "Y")

# Air Ambulance Map
PA_terrain + 
  geom_point(aes(x = x, y = y),
             data = Air_Ambulance, 
             col="red", alpha = 0.4)

# Hospitals with ICU facility 
ICU <- PA_Hospitals %>%
  filter(!is.na(icu)) %>%
  filter(icu == "Y")

PA_terrain + 
  geom_point(aes(x = x, y = y),
             data = ICU, 
             col= "red", alpha = 0.2)

# Organ Bank locations 
Organ_Bank <- PA_Hospitals %>%
  filter(!is.na(organ_bank)) %>%
  filter(organ_bank == "Y")

# Organ Bank Map
PA_terrain + 
  geom_point(aes(x = x, y = y),
             data = Organ_Bank, 
             col="red", alpha = 0.4)

# Bed_sus density in PA state
Beds_sus <- PA_Hospitals %>%
  filter(!is.na(beds_sus))

PA_terrain + 
  geom_density2d(data = Beds_sus, aes(x = x, y = y), size = 0.3) + 
  stat_density2d(data = Beds_sus, 
                 aes(x = x, y = y, 
                     fill = ..level.., 
                     alpha = ..level..), 
                 size = 0.01, 
                 bins = 16, geom = "polygon") + 
  scale_fill_gradient(low = "green", high = "red") + 
  scale_alpha(range = c(0,0.3), 
              guide = FALSE)

# Hospitals in Philadelphia city with liver transplant facility 
Liver_transplant <- PA_Hospitals %>%
  filter(!is.na(liver_tran)) %>%
  filter(liver_tran == "Y" & city == "Philadelphia")

Philly_tonerlite + 
  geom_point(aes(x = x, y = y),
             data = Liver_transplant, 
             col="red", alpha = 0.6)