Objectives

Using the spatial visualization techniques, explore this data set on Pennsylvania hospitals (http://www.arcgis.com/home/item.html?id=eccee5dfe01e4c4283c9be0cfc596882). Create a series of 5 maps that highlight spatial differences in hospital service coverage for the state of PA.

To help you in getting the data imported into R, I have included the code below:

To import the data I use the foreign package, if you do not have it than be sure to install it prior to testing the code.

library(ggplot2)
library(foreign)
library(ggmap)
## Warning: package 'ggmap' was built under R version 4.0.2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(ggthemes)
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

The dataset contains a number of variables about each hospital, many of them are clear and straight forward.

dat <- read.dbf("C:/Users/Ruchil/OneDrive/MS_Analytics_HU/2ndSemester/ANLY_565/R_script/pennsylv.dbf")  # change this to connect to your version
View(dat)

Now create 5 maps, including descriptions, that highlight the spatial distribution of hospital services in the state of PA. Upload these maps as a document to rpubs.com and submit that link to the Canvas assignment.

Pi <- subset(dat, city == "Pittsburgh")
 qmplot(x, y, data = Pi, colour = I("red"), size = I(3), darken = .3, zoom=12, extent="panel",main ="Hospitals in Pittsburgh")
## Source : http://tile.stamen.com/terrain/12/1136/1541.png
## Source : http://tile.stamen.com/terrain/12/1137/1541.png
## Source : http://tile.stamen.com/terrain/12/1138/1541.png
## Source : http://tile.stamen.com/terrain/12/1139/1541.png
## Source : http://tile.stamen.com/terrain/12/1136/1542.png
## Source : http://tile.stamen.com/terrain/12/1137/1542.png
## Source : http://tile.stamen.com/terrain/12/1138/1542.png
## Source : http://tile.stamen.com/terrain/12/1139/1542.png
## Source : http://tile.stamen.com/terrain/12/1136/1543.png
## Source : http://tile.stamen.com/terrain/12/1137/1543.png
## Source : http://tile.stamen.com/terrain/12/1138/1543.png
## Source : http://tile.stamen.com/terrain/12/1139/1543.png
## Source : http://tile.stamen.com/terrain/12/1136/1544.png
## Source : http://tile.stamen.com/terrain/12/1137/1544.png
## Source : http://tile.stamen.com/terrain/12/1138/1544.png
## Source : http://tile.stamen.com/terrain/12/1139/1544.png
## Source : http://tile.stamen.com/terrain/12/1136/1545.png
## Source : http://tile.stamen.com/terrain/12/1137/1545.png
## Source : http://tile.stamen.com/terrain/12/1138/1545.png
## Source : http://tile.stamen.com/terrain/12/1139/1545.png
## Source : http://tile.stamen.com/terrain/12/1136/1546.png
## Source : http://tile.stamen.com/terrain/12/1137/1546.png
## Source : http://tile.stamen.com/terrain/12/1138/1546.png
## Source : http://tile.stamen.com/terrain/12/1139/1546.png

Trauma <- subset(dat, acc_trauma == "Y" )
qmplot(x, y, data = Trauma,zoom = 8) +
stat_bin2d(aes(x,y, colour = ct_scan, fill = ct_scan),
    size = .5, bins = 30, alpha = 2/4, data = Trauma) +
   scale_colour_discrete("ct_scan",labels = c("Yes","No"),guide = FALSE) +
   scale_fill_discrete("CT Scan",labels = c("Yes","No")) +
   theme(legend.text = element_text(size = 15, vjust = .5),
     legend.title = element_text(size = 15,face="bold"),
     legend.key.size = grid::unit(1.8,"lines"))+
  ggtitle("CT scan Available at Trauma centers")
## Source : http://tile.stamen.com/terrain/8/70/94.png
## Source : http://tile.stamen.com/terrain/8/71/94.png
## Source : http://tile.stamen.com/terrain/8/72/94.png
## Source : http://tile.stamen.com/terrain/8/73/94.png
## Source : http://tile.stamen.com/terrain/8/74/94.png
## Source : http://tile.stamen.com/terrain/8/70/95.png
## Source : http://tile.stamen.com/terrain/8/71/95.png
## Source : http://tile.stamen.com/terrain/8/72/95.png
## Source : http://tile.stamen.com/terrain/8/73/95.png
## Source : http://tile.stamen.com/terrain/8/74/95.png
## Source : http://tile.stamen.com/terrain/8/70/96.png
## Source : http://tile.stamen.com/terrain/8/71/96.png
## Source : http://tile.stamen.com/terrain/8/72/96.png
## Source : http://tile.stamen.com/terrain/8/73/96.png
## Source : http://tile.stamen.com/terrain/8/74/96.png
## Source : http://tile.stamen.com/terrain/8/70/97.png
## Source : http://tile.stamen.com/terrain/8/71/97.png
## Source : http://tile.stamen.com/terrain/8/72/97.png
## Source : http://tile.stamen.com/terrain/8/73/97.png
## Source : http://tile.stamen.com/terrain/8/74/97.png

qmplot(x, y, data = Pi,zoom=12) +
   geom_point(aes(x, y, colour = typ_org,size=I(3)), data = Pi) +
   theme(
     legend.key.size = grid::unit(1.8,"lines"),
     legend.title = element_text(size = 16, face = "bold"),
     legend.text = element_text(size = 14)
   ) +
   labs(colour = "Type of Organization", size = "Ultra sound",main="Type of Organization in Pittsburg")+
  ggtitle("Types of Organizations in Pittsburg")

Philadelphia = subset(dat,city == "Philadelphia")
qmplot(x, y, data = Philadelphia,maptype = 'toner-2011',zoom=12)+
  geom_point(aes(x,y, color = liver_tran),
    size = 2, bins = 4, data = Philadelphia, geom = "polygon") +
    scale_fill_gradient2( midpoint = 1000) +
  scale_alpha(range = c(.2, .75), guide = FALSE) +
  scale_colour_discrete("Liver transplant")+
     ggtitle("Liver transplant available in Philidelphia hospitals")
## Source : http://tile.stamen.com/terrain/12/1191/1549.png
## Source : http://tile.stamen.com/terrain/12/1192/1549.png
## Source : http://tile.stamen.com/terrain/12/1193/1549.png
## Source : http://tile.stamen.com/terrain/12/1194/1549.png
## Source : http://tile.stamen.com/terrain/12/1195/1549.png
## Source : http://tile.stamen.com/terrain/12/1191/1550.png
## Source : http://tile.stamen.com/terrain/12/1192/1550.png
## Source : http://tile.stamen.com/terrain/12/1193/1550.png
## Source : http://tile.stamen.com/terrain/12/1194/1550.png
## Source : http://tile.stamen.com/terrain/12/1195/1550.png
## Source : http://tile.stamen.com/terrain/12/1191/1551.png
## Source : http://tile.stamen.com/terrain/12/1192/1551.png
## Source : http://tile.stamen.com/terrain/12/1193/1551.png
## Source : http://tile.stamen.com/terrain/12/1194/1551.png
## Source : http://tile.stamen.com/terrain/12/1195/1551.png
## Warning: Ignoring unknown parameters: bins, geom

Philadelphia = subset(dat,city == "Philadelphia")


qmplot(x, y, data = Philadelphia, maptype = "toner-lite",zoom=12,
  color = typ_serv,size=I(3))+
     geom_point(aes(x,y, colour = typ_serv), data = Philadelphia) +
   scale_colour_discrete("Type of Service")  +
   guides(size = guide_legend(override.aes = list(size = 6))) +
   theme(
     legend.key.size = grid::unit(1.8,"lines"),
     legend.title = element_text(size = 16, face = "bold"),
     legend.text = element_text(size = 14)
   ) +
   ggtitle("Type of service Philadelphia Hospital Offer")