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(foreign)
library(ggplot2)
library(ggmap)
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
dat <- read.dbf("pennsylv.dbf") # change this to connect to your version
The dataset contains a number of variables about each hospital, many of there 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"
Now create 5 maps, including decriptions, 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 the Moodle assignment.
This map shows all hospitals located in PA categorized by type of services assigned by different colors. We can see that hospitals with General Madical and Surgical service seems to be the majority based on the brown dots spreading all over the state. Also, it is noticable that there are many hospitals clustered in these two cities, Pittsburgh and Philadelphia.
qmplot(x, y, data = dat, colour = dat$typ_serv, mapcolor = "color", extent = "panel", main = "Hospital Location in PA by Type of Services", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'roadmap', zoom = 7)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.942826,-77.681596&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false
Now let’s investigate further into those two cities, we start with Pittsburgh. We would like to know the location of hospitals that provide surgical service. The map shows there are not so many hospitals in Pittsburgh that provide the service. By using sum(), now we know that there are exactly 5 hospitals.
pittsburgh <- subset(dat, city == "Pittsburgh")
pbSurgical <- subset(pittsburgh, surgical =="Y")
qmplot(x, y, data = pbSurgical, legend = "none", colour= I('red'), mapcolor = "color", extent = "panel", darken = 0.1, main = "Hospitals in Pittsburgh with Surgical Service", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'terrain', size = I(2), zoom = 10)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.437147,-79.92559&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
sum(pbSurgical$surgical == "Y") # to count the exact number of hospitals
## [1] 5
The map shows the location and that there are only 4 hospitals in Pittsburgh with organ bank.
pbOrganbank <- subset(pittsburgh, organ_bank=="Y")
qmplot(x,y, data = pbOrganbank, colour = I('blue'), size = I(4), zoom = 11, extent = "device", source = "google", maptype = "toner", main = "Hospitals in Pittsburgh with Organ Bank", xlab = "Longitude", ylab = "Latitude")
## maptype = "toner" is only available with source = "stamen".
## resetting to source = "stamen"...
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.499521,-80.002839&zoom=11&size=640x640&scale=2&maptype=terrain&sensor=false
## Map from URL : http://tile.stamen.com/toner/11/567/770.png
## Map from URL : http://tile.stamen.com/toner/11/568/770.png
## Map from URL : http://tile.stamen.com/toner/11/569/770.png
## Map from URL : http://tile.stamen.com/toner/11/570/770.png
## Map from URL : http://tile.stamen.com/toner/11/567/771.png
## Map from URL : http://tile.stamen.com/toner/11/568/771.png
## Map from URL : http://tile.stamen.com/toner/11/569/771.png
## Map from URL : http://tile.stamen.com/toner/11/570/771.png
## Map from URL : http://tile.stamen.com/toner/11/567/772.png
## Map from URL : http://tile.stamen.com/toner/11/568/772.png
## Map from URL : http://tile.stamen.com/toner/11/569/772.png
## Map from URL : http://tile.stamen.com/toner/11/570/772.png
## Warning: `panel.margin` is deprecated. Please use `panel.spacing` property
## instead
sum(pbOrganbank$organ_bank == "Y")
## [1] 4
Now let’s have a look at Philadelphia. This map below shows location of the hospitals that provide Chemo service. The service seems to be available in many hospitals over the city.
philadelphia <- subset(dat, city == "Philadelphia")
phil.chemo <- subset(philadelphia, chemo == "Y")
qmplot(x, y, data = phil.chemo, colour = I('green'), size = I(3), zoom = 12, extent = "panel", source = "google", maptype = "hybrid", main = "Hospitals with Chemo Service in Philadelphia", xlab = "Longitude", ylab = "Latitude")
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.012589,-75.136495&zoom=12&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false
This last map shows location of hospitals with ICU in Philadelphia and numbers of beds represented by size of the dots.
phil.icu <- subset(philadelphia, icu == "Y")
qmplot(x, y, data = phil.icu, color = 'orange', size = phil.icu$icu_beds, mapcolor = "color", extent = "panel", main = "Location of Hospitals with ICU and Number of Beds in Philadelphia", xlab = "Longitude", ylab = "Latitude", source = 'google', maptype = 'roadmap', zoom = 12)
## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.009448,-75.126851&zoom=12&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false