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.
#install.packages('foregin')
library(foreign)
dat <- read.dbf("/Users/zosiajiang/Downloads/pennsylv/pennsylv.dbf") # change this to connect to your version
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"
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 the Canvas assignment.
library(ggplot2)
library(ggmap)
## 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(tidyverse)
## ── Attaching packages ────────────────────────────── tidyverse 1.3.0 ──
## ✓ tibble 3.0.3 ✓ dplyr 1.0.2
## ✓ tidyr 1.1.2 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ✓ purrr 0.3.4
## ── Conflicts ───────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
register_google(key = "AIzaSyAwABjvVbCDahXW1PEj6u0QID-r4ICLsVg")
# The number of ICU
library(dplyr)
dat %>% select(icu, icu_beds, x, y) -> ICU
ICU <- subset(ICU, ICU$icu =='Y' )
ICU %>% drop_na() -> ICU
PA <- get_map("PA",zoom = 7, maptype = "toner-background")
## maptype = "toner-background" is only available with source = "stamen".
## resetting to source = "stamen"...
## Source : https://maps.googleapis.com/maps/api/staticmap?center=PA&zoom=7&size=640x640&scale=2&maptype=terrain&key=xxx-r4ICLsVg
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=PA&key=xxx-r4ICLsVg
## Source : http://tile.stamen.com/toner-background/7/35/46.png
## Source : http://tile.stamen.com/toner-background/7/36/46.png
## Source : http://tile.stamen.com/toner-background/7/37/46.png
## Source : http://tile.stamen.com/toner-background/7/35/47.png
## Source : http://tile.stamen.com/toner-background/7/36/47.png
## Source : http://tile.stamen.com/toner-background/7/37/47.png
## Source : http://tile.stamen.com/toner-background/7/35/48.png
## Source : http://tile.stamen.com/toner-background/7/36/48.png
## Source : http://tile.stamen.com/toner-background/7/37/48.png
## Source : http://tile.stamen.com/toner-background/7/35/49.png
## Source : http://tile.stamen.com/toner-background/7/36/49.png
## Source : http://tile.stamen.com/toner-background/7/37/49.png
ggmap(PA) +
geom_point(mapping = aes(x= x, y=y,size = icu_beds), color = 'red',data = ICU) +
xlab('Longitude') +
ylab('Latitude') +
ggtitle('ICU Distribution of Pennsylvania')
Based on the Map 1, we can tell that hospitals have ICU departments are mainly at west and east of PA. Hospitals that have more ICU beds mainly around Philadelphia, Allentown, and Pittsburgh areas.
# Type of Organization
summary(dat$typ_org)
## Church Operated Corporation Individual
## 7 62 1
## Non-profit Corp. Other,Not For Profit Partnership
## 142 20 8
## State Unknown VA
## 8 4 3
## NA's
## 20
PA2 <- get_map("PA",zoom = 7, maptype = "watercolor")
## maptype = "watercolor" is only available with source = "stamen".
## resetting to source = "stamen"...
## Source : https://maps.googleapis.com/maps/api/staticmap?center=PA&zoom=7&size=640x640&scale=2&maptype=terrain&key=xxx-r4ICLsVg
## Source : https://maps.googleapis.com/maps/api/geocode/json?address=PA&key=xxx-r4ICLsVg
## Source : http://tile.stamen.com/watercolor/7/35/46.jpg
## Source : http://tile.stamen.com/watercolor/7/36/46.jpg
## Source : http://tile.stamen.com/watercolor/7/37/46.jpg
## Source : http://tile.stamen.com/watercolor/7/35/47.jpg
## Source : http://tile.stamen.com/watercolor/7/36/47.jpg
## Source : http://tile.stamen.com/watercolor/7/37/47.jpg
## Source : http://tile.stamen.com/watercolor/7/35/48.jpg
## Source : http://tile.stamen.com/watercolor/7/36/48.jpg
## Source : http://tile.stamen.com/watercolor/7/37/48.jpg
## Source : http://tile.stamen.com/watercolor/7/35/49.jpg
## Source : http://tile.stamen.com/watercolor/7/36/49.jpg
## Source : http://tile.stamen.com/watercolor/7/37/49.jpg
ggmap(PA2) +
geom_point(mapping = aes(x=x, y=y, colour = typ_org, size = 4, alpha=0.8), data = dat) +
xlab('Longitude') +
ylab('Latitude') +
ggtitle('Hospitals Organization Types of Pennsylvania')
From Map 2, we can tell that Non-profit Corp is the main type of hospital organization in PA.
# Type of Service
summary(dat$typ_serv)
## Alcoholism-Drug Abuse General Medical and Surgical
## 3 167
## Long-term Acute Care Other
## 27 11
## Psychiatric Rehabilitation
## 25 18
## Unknown NA's
## 4 20
str(dat$typ_serv)
## Factor w/ 7 levels "Alcoholism-Drug Abuse",..: 2 2 2 2 5 2 2 2 2 2 ...
qmplot(x, y, data = dat,
colour = typ_serv, size = I(3), darken = .3,
extent = 'panel',
main = 'Hopsitals Service Types in Pennsylvania',
xla = 'Longitude',
ylab= 'Latitude')
## 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: xla
From map 3, we can see that the majority of hospitals in PA offer general medical and surgical service, scattered around PA.Psychiatric service is mainly located at east side of PA.
# Social Worker Y/N
dat %>% select(social_wor,x,y) -> soc_wor
soc_wor <- subset(soc_wor, soc_wor$social_wor =='Y' )
soc_wor %>% drop_na() -> soc_wor
library(leaflet)
leaflet() %>%
addTiles() %>%
addMarkers(lng=soc_wor$x, lat=soc_wor$y, soc_wor)
From Map 4, we can tell the social workers are throughout the hospitals in PA, esp concentrate at the east side cities, around Philadelphia.
# Pharmacy -Y/N
dat %>% select(hosp_id,pharmacy,x,y) -> pharmacy
pharmacy <- subset(pharmacy, pharmacy =='Y' )
pharmacy %>% drop_na() -> pharmacy
leaflet() %>% addTiles() %>%
addMarkers(pharmacy$x,pharmacy$y, pharmacy,
popup = pharmacy$hosp_id
)
Compared with the distribution of social workers, pharmacies are more well equipped throughout the PA, even if at the middle of PA.