Homework 5

Using spatial visualization techniques available in R, explore the attached data set on Pennsylvania hospitals,

Create a series of 5 maps that highlight spatial differences in hospital service coverage for the state of PA.
The dataset contains a number of variables about each hospital, many of them are clear and straight forward. Note: the variables “x” and “Y” are the longitude and latitude data.

For this assignment, create 5 maps. Each map should have an accompanying description that is detailed and clearly written. Make note of any spatial patterns or anomalies of hospital services that you see in the state of PA. Upload these maps as a document to rpubs.com and submit that link the Moodle assignment.

library(foreign)
library(ggplot2)
library(ggmap)
dat <- read.dbf("/Users/cristinasoleperez/Desktop/Data Visualization/pennsylv.dbf")
summary(dat)
##  acc_trauma air_amb      als                   arc_street     arc_zone  
##  N:243      N   :226   N   :212   1 Hospital Dr     :  4   18702  :  6  
##  Y: 32      Y   : 23   Y   : 37   100 N Academy Ave :  2   15213  :  5  
##             NA's: 26   NA's: 26   1001 S George St  :  2   19104  :  5  
##                                   1086 Franklin St  :  2   16602  :  4  
##                                   1500 Lansdowne Ave:  2   16507  :  3  
##                                   250 S 21st St     :  2   17042  :  3  
##                                   (Other)           :261   (Other):249  
##   bas_ls      bassinets         bb_id        bc_beds        bc_sus_bed   
##  N   :220   Min.   : 3.00   1      :  1   Min.   : 7.00   Min.   : 7.00  
##  Y   : 29   1st Qu.:10.75   100    :  1   1st Qu.:10.25   1st Qu.:10.25  
##  NA's: 26   Median :15.00   101    :  1   Median :14.00   Median :14.50  
##             Mean   :18.28   102    :  1   Mean   :13.33   Mean   :13.33  
##             3rd Qu.:22.00   103    :  1   3rd Qu.:17.00   3rd Qu.:16.50  
##             Max.   :80.00   104    :  1   Max.   :18.00   Max.   :18.00  
##             NA's   :171     (Other):269   NA's   :269     NA's   :269    
##     beds_sus        birthing_r     bone_marro burn_car   burn_care 
##  Min.   :  10.0   Min.   : 1.000   N   :237   N   :228   N   :243  
##  1st Qu.:  50.0   1st Qu.: 3.000   Y   : 12   Y   : 21   Y   :  6  
##  Median : 102.0   Median : 4.000   NA's: 26   NA's: 26   NA's: 26  
##  Mean   : 164.8   Mean   : 5.961                                   
##  3rd Qu.: 209.2   3rd Qu.: 7.000                                   
##  Max.   :1485.0   Max.   :22.000                                   
##  NA's   :31       NA's   :224                                      
##    card_beds      card_surge   card_sus_b     cardiac    cardiac_ca
##  Min.   :  6.00   N   :189   Min.   :  4.00   N   :204   N   :153  
##  1st Qu.: 10.00   Y   : 60   1st Qu.: 10.00   Y   : 45   Y   : 96  
##  Median : 12.00   NA's: 26   Median : 12.00   NA's: 26   NA's: 26  
##  Mean   : 22.98              Mean   : 21.82                        
##  3rd Qu.: 22.00              3rd Qu.: 19.00                        
##  Max.   :189.00              Max.   :177.00                        
##  NA's   :230                 NA's   :230                           
##  cardio_reh  chemo               city     clin_lab   clin_psych
##  N   :118   N   :119   Philadelphia: 39   N   : 62   N   :123  
##  Y   :131   Y   :130   Pittsburgh  : 22   Y   :187   Y   :126  
##  NA's: 26   NA's: 26   Allentown   :  7   NA's: 26   NA's: 26  
##                        Erie        :  7                        
##                        Wilkes-Barre:  6                        
##                        Altoona     :  4                        
##                        (Other)     :190                        
##           county           countyname  ct_scan       cty_key    cystoscopi
##  Philadelphia: 39   Philadelphia: 40   N   : 80   42101  : 40   N   :174  
##  Allegheny   : 32   Allegheny   : 32   Y   :169   42003  : 32   Y   : 75  
##  Montgomery  : 14   Montgomery  : 14   NA's: 26   42091  : 14   NA's: 26  
##  Lehigh      : 11   Lehigh      : 11              42077  : 11             
##  Chester     : 10   Chester     : 10              42029  : 10             
##  Luzerne     :  9   Luzerne     :  9              42079  :  9             
##  (Other)     :160   (Other)     :159              (Other):159             
##    deliv_rms       dental    detox_alc_ diag_radio diag_xray  doh_hosp
##  Min.   : 1.000   N   :222   N   :205   N   : 96   N   : 52   N: 20   
##  1st Qu.: 1.000   Y   : 27   Y   : 44   Y   :153   Y   :197   Y:255   
##  Median : 2.000   NA's: 26   NA's: 26   NA's: 26   NA's: 26           
##  Mean   : 2.234                                                       
##  3rd Qu.: 2.000                                                       
##  Max.   :12.000                                                       
##  NA's   :228                                                          
##       doh_phone   emer_dept  endoscopie     fac_id   
##  7177823131:  2   N   : 87   N   :125   0      : 17  
##  8148892011:  2   Y   :162   Y   :124   0618   :  3  
##  2152336200:  1   NA's: 26   NA's: 26   0128   :  2  
##  2152488200:  1                         0836   :  2  
##  2153324500:  1                         1037   :  2  
##  (Other)   :250                         0020   :  1  
##  NA's      : 18                         (Other):248  
##                            facility   flu_old   
##  Altoona Regional Health System:  2   N   : 33  
##  Pinnacle Health Hospitals     :  2   Y   :216  
##  Abington Memorial Hospital    :  1   NA's: 26  
##  Albert Einstein Medical Center:  1             
##  Alle-Kiski Medical Center     :  1             
##  Allegheny General Hospital    :  1             
##  (Other)                       :267             
##                             fred_con_1             fred_conta 
##  Emergency Management Coordinator:  4   Armand Alessi   :  2  
##  ER Nurse Manager                :  4   Chris Coforio   :  2  
##  Nurse Manager                   :  4   Mike Rosensteel :  2  
##  Safety Officer                  :  4   Steve Jakubcanin:  2  
##  Administrator                   :  3   Adam Bakaj      :  1  
##  (Other)                         :171   (Other)         :235  
##  NA's                            : 85   NA's            : 31  
##                          fred_email        fred_fax   fred_hosp
##  bburger@selectmedicalcorp.com:  3   6103941853:  2   N:  6    
##  armand.alessi@crozer.org     :  2   7249837568:  2   Y:269    
##  brenda.miller-reeser@lvh.com :  2   2152465451:  1            
##  coforioc@email.chop.edu      :  2   2152488070:  1            
##  mrosensteel@excelahealth.org :  2   2152913617:  1            
##  (Other)                      :246   (Other)   :234            
##  NA's                         : 18   NA's      : 34            
##       fred_pager       fred_phone  gamma_knif gen_outpat gene_counc
##  2155076665:  2   2154568053:  2   N   :236   N   :205   N   :202  
##  4129170105:  2   2672405394:  2   Y   : 13   Y   : 44   Y   : 47  
##  7174991392:  2   6102848599:  2   NA's: 26   NA's: 26   NA's: 26  
##  7246464689:  2   6104026115:  2                                   
##  0000000000:  1   7173587390:  2                                   
##  (Other)   :107   (Other)   :254                                   
##  NA's      :159   NA's      : 11                                   
##  heart_tran helipad hemodial_c hemodial_m    hosp_id    hospice   
##  N   :240   N:155   N   :214   N   :245   0      : 17   N   :152  
##  Y   :  9   Y:120   Y   : 35   Y   :  4   002000 :  1   Y   : 97  
##  NA's: 26           NA's: 26   NA's: 26   002100 :  1   NA's: 26  
##                                           002200 :  1             
##                                           002300 :  1             
##                                           002600 :  1             
##                                           (Other):253             
##  hyper_cham   icu         icu_beds        icu_sus_be      inpat_flu_    
##  N   :199   N   :180   Min.   :  2.00   Min.   :  2.0   Min.   :   1.0  
##  Y   : 50   Y   : 69   1st Qu.:  8.00   1st Qu.:  8.0   1st Qu.:  25.0  
##  NA's: 26   NA's: 26   Median : 12.00   Median : 12.0   Median : 123.0  
##                        Mean   : 21.91   Mean   : 20.8   Mean   : 260.8  
##                        3rd Qu.: 22.00   3rd Qu.: 20.0   3rd Qu.: 393.2  
##                        Max.   :198.00   Max.   :194.0   Max.   :2420.0  
##                        NA's   :208      NA's   :206     NA's   :67      
##    inpat_pneu     kidney_tra   labor_rms         lic_beds     
##  Min.   :   1.0   N   :234   Min.   : 1.000   Min.   :  10.0  
##  1st Qu.:  24.0   Y   : 15   1st Qu.: 2.000   1st Qu.:  55.0  
##  Median : 135.0   NA's: 26   Median : 3.000   Median : 116.0  
##  Mean   : 313.6              Mean   : 3.423   Mean   : 176.7  
##  3rd Qu.: 419.0              3rd Qu.: 4.000   3rd Qu.: 214.0  
##  Max.   :3100.0              Max.   :10.000   Max.   :1573.0  
##  NA's   :74                  NA's   :249      NA's   :34      
##     lic_dent        lic_dos          lic_mds           lic_pod      
##  Min.   : 1.00   Min.   :  1.00   Min.   :   1.00   Min.   : 1.000  
##  1st Qu.: 1.00   1st Qu.:  5.00   1st Qu.:  22.75   1st Qu.: 2.000  
##  Median : 3.00   Median : 17.00   Median :  79.50   Median : 5.000  
##  Mean   : 6.92   Mean   : 25.32   Mean   : 171.17   Mean   : 8.132  
##  3rd Qu.: 7.75   3rd Qu.: 34.50   3rd Qu.: 196.00   3rd Qu.:11.750  
##  Max.   :74.00   Max.   :184.00   Max.   :1887.00   Max.   :37.000  
##  NA's   :137     NA's   :48       NA's   :33        NA's   :101     
##  linear_acc lithotrips liver_tran loc_method   ltc           mcd     
##  N   :182   N   :155   N   :237   G: 13      N   :196   60000  : 40  
##  Y   : 67   Y   : 94   Y   : 12   R:262      Y   : 53   61000  : 15  
##  NA's: 26   NA's: 26   NA's: 26              NA's: 26   24000  :  6  
##                                                         02000  :  4  
##                                                         46656  :  4  
##                                                         69000  :  4  
##                                                         (Other):202  
##        mcd_key                 mcd_name   medical    mob_ccu    mob_icu   
##  4210160000: 40   Philadelphia     : 35   N   :188   N   :244   N   :236  
##  4200361000: 15   Pittsburgh       : 13   Y   : 61   Y   :  5   Y   : 13  
##  4204924000:  6   Erie City        :  6   NA's: 26   NA's: 26   NA's: 26  
##  4206969000:  4   Philadelphia City:  5                                   
##  4207702000:  4   Allentown City   :  4                                   
##  4209346656:  4   Mahoning Township:  4                                   
##  (Other)   :202   (Other)          :208                                   
##    mri                         ms1        neo2_beds        neo2_sus_b    
##  N   : 91   Limerick             :  4   Min.   : 2.000   Min.   : 1.000  
##  Y   :158   TMI                  :  4   1st Qu.: 4.000   1st Qu.: 3.000  
##  NA's: 26   Susquehanna          :  3   Median : 6.000   Median : 5.000  
##             Beaver               :  2   Mean   : 7.892   Mean   : 7.351  
##             Limerick/Peach Bottom:  1   3rd Qu.:10.000   3rd Qu.: 9.000  
##             (Other)              :  2   Max.   :27.000   Max.   :27.000  
##             NA's                 :259   NA's   :238      NA's   :238     
##    neo3_beds       neo3_sus_b    neuro_surg neurology  obs_gyn   
##  Min.   : 2.00   Min.   : 2.00   N   :149   N   :101   N   :203  
##  1st Qu.:14.00   1st Qu.:13.00   Y   :100   Y   :148   Y   : 46  
##  Median :17.00   Median :17.00   NA's: 26   NA's: 26   NA's: 26  
##  Mean   :22.91   Mean   :21.97                                   
##  3rd Qu.:30.00   3rd Qu.:28.00                                   
##  Max.   :75.00   Max.   :66.00                                   
##  NA's   :242     NA's   :242                                     
##  occ_ther   optometry  organ_bank    ped_trauma  pediatric    pet     
##  N   : 26   N   :198   N   :228   Level I :  4   N   :220   N   :163  
##  Y   :223   Y   : 51   Y   : 21   Level II:  2   Y   : 29   Y   : 86  
##  NA's: 26   NA's: 26   NA's: 26   NA's    :269   NA's: 26   NA's: 26  
##                                                                       
##                                                                       
##                                                                       
##                                                                       
##  pharmacy   phys_med   phys_ther  podiatry     providerid      psych    
##  N   : 30   N   :204   N   : 28   N   : 86   Min.   :  68.0   N   :214  
##  Y   :219   Y   : 45   Y   :221   Y   :163   1st Qu.: 177.2   Y   : 35  
##  NA's: 26   NA's: 26   NA's: 26   NA's: 26   Median : 273.5   NA's: 26  
##                                              Mean   : 898.1             
##                                              3rd Qu.:2412.2             
##                                              Max.   :2587.0             
##                                              NA's   :1                  
##  psych_inpa     reg_trauma  resp_ther  so_flu_65u social_wor speech_pat
##  N   :124   Level I  : 14   N   : 37   N   : 78   N   : 12   N   : 41  
##  Y   :125   Level II : 13   Y   :212   Y   :171   Y   :237   Y   :208  
##  NA's: 26   Level III:  2   NA's: 26   NA's: 26   NA's: 26   NA's: 26  
##             NA's     :246                                              
##                                                                        
##                                                                        
##                                                                        
##                       street    surgical   surgical_s thera_radi
##  One Hospital Drive      :  3   N   :195   N   : 74   N   :172  
##  1000 Dutch Ridge Road   :  2   Y   : 54   Y   :175   Y   : 77  
##  200 Lothrop Street      :  2   NA's: 26   NA's: 26   NA's: 26  
##  250 South 21st Street   :  2                                   
##  2545 Schoenersville Road:  2                                   
##  620 Howard Avenue       :  2                                   
##  (Other)                 :262                                   
##                  typ_org                            typ_serv   ultrasound
##  Non-profit Corp.    :142   General Medical and Surgical:167   N   : 68  
##  Corporation         : 62   Long-term Acute Care        : 27   Y   :181  
##  Other,Not For Profit: 20   Psychiatric                 : 25   NA's: 26  
##  Partnership         :  8   Rehabilitation              : 18             
##  State               :  8   Other                       : 11             
##  (Other)             : 15   (Other)                     :  7             
##  NA's                : 20   NA's                        : 20             
##        x                y              zip     
##  Min.   :-80.50   Min.   :39.75   19104  :  5  
##  1st Qu.:-79.20   1st Qu.:40.05   15213  :  4  
##  Median :-76.45   Median :40.41   15224  :  3  
##  Mean   :-77.15   Mean   :40.55   17105  :  3  
##  3rd Qu.:-75.36   3rd Qu.:40.87   17405  :  3  
##  Max.   :-74.87   Max.   :42.13   17822  :  3  
##                                   (Other):254

Map 1 - This maps represents the Surgical Hospitals in the PA state. It is clear how there is some consolidation along key cities in Pensilvania such as Pittsburg and Philadeplhia

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.995052,-77.729609&zoom=7&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false

Map 2 - Given our first initial plot, we want to understand better the distribution nearby major cities in Pensilvania. Map #2 will show Surgical Hospitals nearby Pittsburgh and Map #3 will show the same for Philadephia

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.437147,-79.92559&zoom=11&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false

Map 3 - As discribed in Map #2, Map #3 represent the same deep dive, but for Philadelphia (County)

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.009448,-75.143337&zoom=11&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false

Map 4- Mapping of PA Hospitals with Dental Care

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.953446,-77.561862&zoom=7&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false

Map 5 -Mapping of all Surgical hospitals represented in Map #1 but with the sub-classification of which ones have MRIs

## Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=40.009448,-75.143337&zoom=11&size=640x640&scale=2&maptype=hybrid&language=en-EN&sensor=false