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.

#Import dataset and get the google API key.

df <- rio::import("pennsylv.dbf")
register_google(key = 'AIzaSyDak80zxXvXLYE-1WxJ0qWDrII8OSkNFvM')

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

names(df)
##   [1] "acc_trauma" "air_amb"    "als"        "arc_street" "arc_zone"  
##   [6] "bas_ls"     "bassinets"  "bb_id"      "bc_beds"    "bc_sus_bed"
##  [11] "beds_sus"   "birthing_r" "bone_marro" "burn_car"   "burn_care" 
##  [16] "card_beds"  "card_surge" "card_sus_b" "cardiac"    "cardiac_ca"
##  [21] "cardio_reh" "chemo"      "city"       "clin_lab"   "clin_psych"
##  [26] "county"     "countyname" "ct_scan"    "cty_key"    "cystoscopi"
##  [31] "deliv_rms"  "dental"     "detox_alc_" "diag_radio" "diag_xray" 
##  [36] "doh_hosp"   "doh_phone"  "emer_dept"  "endoscopie" "fac_id"    
##  [41] "facility"   "flu_old"    "fred_con_1" "fred_conta" "fred_email"
##  [46] "fred_fax"   "fred_hosp"  "fred_pager" "fred_phone" "gamma_knif"
##  [51] "gen_outpat" "gene_counc" "heart_tran" "helipad"    "hemodial_c"
##  [56] "hemodial_m" "hosp_id"    "hospice"    "hyper_cham" "icu"       
##  [61] "icu_beds"   "icu_sus_be" "inpat_flu_" "inpat_pneu" "kidney_tra"
##  [66] "labor_rms"  "lic_beds"   "lic_dent"   "lic_dos"    "lic_mds"   
##  [71] "lic_pod"    "linear_acc" "lithotrips" "liver_tran" "loc_method"
##  [76] "ltc"        "mcd"        "mcd_key"    "mcd_name"   "medical"   
##  [81] "mob_ccu"    "mob_icu"    "mri"        "ms1"        "neo2_beds" 
##  [86] "neo2_sus_b" "neo3_beds"  "neo3_sus_b" "neuro_surg" "neurology" 
##  [91] "obs_gyn"    "occ_ther"   "optometry"  "organ_bank" "ped_trauma"
##  [96] "pediatric"  "pet"        "pharmacy"   "phys_med"   "phys_ther" 
## [101] "podiatry"   "providerid" "psych"      "psych_inpa" "reg_trauma"
## [106] "resp_ther"  "so_flu_65u" "social_wor" "speech_pat" "street"    
## [111] "surgical"   "surgical_s" "thera_radi" "typ_org"    "typ_serv"  
## [116] "ultrasound" "x"          "y"          "zip"

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

I’ve checked the hospital types in the dataset and there’re 7 types.This map is going to map the distribution of these hospitals by type. Based on the map we could tell that most of the hospitals are General Medical and Surgical, and the southeastern and southwestern PA have more hospital than other areas.

qmplot(x, y, data = df, legend = "NONE", color= typ_serv, mapcolor = "color", extent = "panel",darken = 0.5, main = "PA Hospitals Distribution", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'roadmap', size = I(1), zoom = 7) + labs(color='Type of Service') 
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.942826,-77.681596&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&key=xxx-1WxJ0qWDrII8OSkNFvM

This map is going to find out the hospitals with Pediatric Department and the type of these hospitals. Based on the map we could see that there’re not a lot of hospitals with Pediatric Department, and they’re mostly Non-profit Corp.

pedi = subset(df, pediatric == "Y")

qmplot(x, y, data = pedi, legend = "NULL", color= typ_org, mapcolor = "color", extent = "panel",darken = 0.5, main = "PA Hospitals With Pediatric Department", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'roadmap', size = I(1), zoom = 7) + labs(color = "Type of Organization")
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.860195,-77.45448&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&key=xxx-1WxJ0qWDrII8OSkNFvM

Now let’s move on to another important subject in medical area, organ transplant. I am going to map all the PA hospitals with organ bank. According to the map, most of those hospitals located in southeastern and southwestern PA.

organ = subset(df, organ_bank == "Y")

PennMap = get_map("pennsylvania", zoom = 7, maptype = "toner-lite")
## maptype = "toner-lite" is only available with source = "stamen".
## resetting to source = "stamen"...
## Source : https://maps.googleapis.com/maps/api/staticmap?center=pennsylvania&zoom=7&size=640x640&scale=2&maptype=terrain&key=xxx-1WxJ0qWDrII8OSkNFvM
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=pennsylvania&key=xxx-1WxJ0qWDrII8OSkNFvM
## Source : http://tile.stamen.com/toner-lite/7/35/46.png
## Source : http://tile.stamen.com/toner-lite/7/36/46.png
## Source : http://tile.stamen.com/toner-lite/7/37/46.png
## Source : http://tile.stamen.com/toner-lite/7/35/47.png
## Source : http://tile.stamen.com/toner-lite/7/36/47.png
## Source : http://tile.stamen.com/toner-lite/7/37/47.png
## Source : http://tile.stamen.com/toner-lite/7/35/48.png
## Source : http://tile.stamen.com/toner-lite/7/36/48.png
## Source : http://tile.stamen.com/toner-lite/7/37/48.png
## Source : http://tile.stamen.com/toner-lite/7/35/49.png
## Source : http://tile.stamen.com/toner-lite/7/36/49.png
## Source : http://tile.stamen.com/toner-lite/7/37/49.png
ggmap(PennMap,extent = "device") + geom_point(aes(x,y),data = organ,color = "hotpink", main = "PA Hospital With Organ Bank", xlab = "Longitude", ylab = "Latitude", source = 'google')
## Warning: Ignoring unknown parameters: main, xlab, ylab, source

Dental health has a huge influence on people today. So I wanted to see which hospitals have dental department. Again, only a few has dental department and they’re mainly located in southeastern and southwestern PA.

dental = subset(df, dental == "Y")

qmplot(x, y, data = dental, legend = "None",mapcolor = "color", extent = "panel",darken = 0.2, main = "PA Hospitals With Dental Department", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'roadmap', size = I(1), zoom = 7)
## Source : https://maps.googleapis.com/maps/api/staticmap?center=40.953446,-77.561862&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&key=xxx-1WxJ0qWDrII8OSkNFvM

Last, let’s take a look at the hospitals by amount of beds. The more beds a hospital has means the larger capability to provide treatments. There’re a few hospital with over 1000 beds, some more with 500 -1000, and the rest with lower than 500.

qmplot(x, y, data = df) +
  geom_point(aes(x, y,  color = I('red'), size= beds_sus), alpha = 0.2,legend = "none") +
  ggtitle("Hospitals in Pennsylvania by Bed size")+
  ylab("Latitude") + xlab("Longitude") +
  theme(plot.title = element_text(hjust = 0.5, size = 15, vjust =1.4, face ="bold")) + 
  labs(size = "Amount of Beds")
## Using zoom = 8...
## 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
## Warning: Ignoring unknown parameters: legend
## Warning: Removed 31 rows containing missing values (geom_point).