Pre-requisites

library(foreign)
library(ggmap)
library(ggplot2)

# change this to connect to your version
dat <- read.dbf("C:/Users/shoukhan/Documents/Harrisburg University/Anly-512-Data-Visualization/Summer Course/pennsylv.dbf")

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

names(dat)
##   [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"

Spatial Visualization

1. Hospitals in Pennsylvania with chemo facility

#create a subset
chemo <- subset(dat, chemo == "Y")

#remove missing values
chemo <- chemo[!(is.na(chemo$chemo)), ]

#plot
qmplot(x, y, data = chemo, zoom = 7,source = 'google', maptype = 'roadmap', 
       colour= I('blue'), mapcolor = "color", main = "Hospitals in Pennsylvania with chemo facility", xlab = "Longitude", ylab = "Latitude")

2. Hospital in Pennsylvania with emergency service in greater Philadelpia area

#create a subset
emergency <- subset(dat, emer_dept == "Y" & county=="Philadelphia")

#remove missing values
emergency <- emergency[!(is.na(emergency$emer_dept)) & !(is.na(emergency$county)), ]

#plot
qmplot(x, y, data = emergency, zoom = 12, source = "google", maptype = "toner", colour= I('red'), size=I(3), mapcolor ="color", main = "Hospital in Pennsylvania with emergency service in greater Philadelpia area", xlab = "Longitude", ylab = "Latitude")

3. Hospitals in Pennslyvania with rehab service for people with alcohol addiction

#create a subset
rehab <- subset(dat, detox_alc_ == "Y")

#remove missing values
rehab <- rehab[!(is.na(rehab$detox_alc_)), ]

#plot
qmplot(x, y, data = rehab, zoom = 7,source = 'google', maptype = 'hybrid', 
       colour= I('yellow'), mapcolor = "color", main = "Hospitals in Pennslyvania with rehab service - Alcohol ", xlab = "Longitude", ylab = "Latitude")

4. Hospital distribution in Pennslyvania with different services

dat1 <- dat[!(is.na(dat$typ_serv)), ]


qmplot(x, y, data = dat1, size = I(4), colour=typ_serv, main = "Hospital distribution in Pennslyvania with different services", xlab = "Longitude", ylab = "Latitude", source = "google", maptype = "terrain", zoom = 7, legend = "none")

5. Hospital in Pennsylvania with burn care services

#create a subset
burnCases <- subset(dat, burn_care == "Y")

#remove missing values
burnCases <- burnCases[!(is.na(burnCases$burn_care)), ]

#plot
qmplot(x, y, data = burnCases, zoom = 7,source = 'google', maptype = 'terrain', 
       colour= I('red'), mapcolor = "color", main = "Hospital in Pennsylvania with burn care services ", xlab = "Longitude", ylab = "Latitude")