The analysis will explore the SPatial Hospital Dataset of hospitals in PA. We will go over the data manipulation and visualization to uncover some insights from the dataset.
##import the Hospitals ShapeFiles
Hospitals<-readOGR(dsn = "C:/Users/Rodda Ouma/Downloads/hospitals",layer="pennsylv")
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\Rodda Ouma\Downloads\hospitals", layer: "pennsylv"
## with 275 features
## It has 119 fields
##str(Hospitals)
##REname x and y for the Hospitals Dataset
Hospitals$lon<-Hospitals$x
Hospitals$lat<-Hospitals$y
This map shows the general mapping of locations of the hospitals in Pennslyvnia. As seen below, most hospitals are concentrated on the opposite ends of the State(East, West) around big towns like Pittsburg and Philadelphia.
foo.df <- as(Hospitals, "data.frame")
View(foo.df)
#
##summary(foo.df)
d<-leaflet(Hospitals)%>%
addProviderTiles(providers$CartoDB.Positron) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.50)) %>%
addCircles(lng = ~x, lat = ~y, weight=3, radius =40, fillOpacity=30)
d
The map below details the concentration of hospitals spread across Pennsylavania according to their Type of Severity Classification. As seen below, most hospitals are classified under General Medical and Surgical compared to other categories. Towns like Philadelphia and Pittsburg have a variety of different kinds of hospitals compared to other towns.
f<-foo.df[!is.na(Hospitals$typ_serv),]
g<- f[!f$typ_serv == "Unknown",]
##summary(g$typ_serv)
colorFactors = colorFactor(c('black', 'green','red','blue','purple','grey'), domain = g$typ_serv)
d<-leaflet(g)%>%
addProviderTiles(providers$CartoDB.Positron) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.10))%>%
addCircleMarkers(lng = ~x,lat=~y,color=colorFactors(g$typ_serv), popup= ~facility, stroke = FALSE, fillOpacity= 0.9, radius=4)%>%
addLegend("bottomright", pal = colorFactors, values = ~typ_serv,
title = "Type of Severity Classification",
opacity = 1)
d
We further dive into Psychiatric hospitals and analyze their location and the number of licensed medical doctors in each of them. From the map below, Psychiatric hospitals are few in the State and most are located in Philadelphia. Divine Providence Hospital in the North of PA stands out with having the highest number of licensed medical psychiatric doctors. (the diameter of the circle is relative to the number of licensed medical doctors.)
x<-filter(foo.df, foo.df$typ_serv == "Psychiatric")
View (x)
newmap<-leaflet(x) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.1))%>%
addCircles(lng = ~x, lat = ~y, weight = 2.5,
radius = ~(lic_mds*50), popup = ~facility)
newmap
In the map below, we look at the types of hospitals according to their organizational category. Most hospitals are categorized under “Non -profit Corporations” and they are spread out evenly across the State. On the map, they are labelled with red icons.
Interestingly, the church operated hospitals( purple icon) are all located in or around Philadelphia.
y <-foo.df[!is.na(Hospitals$typ_org),]
new_y<- y[!y$typ_org == "Unknown",]
##summary(new_y$typ_org)
getColor <- function(new_y) {
sapply(new_y$typ_org, function(typ_org) {
if(typ_org == "Non-profit Corp.") {
"red"
} else if(typ_org == "Corporation") {
"orange"
} else if (typ_org == "Partnership "){
"black"
} else if (typ_org =="Other,Not For Profit"){
"yellow"
}else if (typ_org == "Church Operated"){
"purple"
}
else if (typ_org == "State") {
"grey"
} else{
"blue"
}
})
}
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = getColor(new_y)
)
h<-leaflet(new_y) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.1)) %>%
addAwesomeMarkers(~x, ~y, icon=icons, label=~as.character(typ_org))
h
We also dive into General Medical and Surgical hospitals and analyze their location and filter out and analyze the number of ICU beds in such hospitals. From the map below, most General Medical and Surgical hospitals are located in or around Philadelphia. However, the General Medical and Surgical hospitals with the highest number of ICU beds are located in Pittsburg. UPMC Presbyterian Shadyside in Pittsburg stands out with the highest number of ICU beds, followed by Allegheny General Hospital located in the same town. (The diameter of the circle is relative to the number of ICU beds in the Hospital)
##summary(foo.df)
p<-filter(foo.df, foo.df$typ_serv == "General Medical and Surgical")
p1<-p[!is.na(p$icu_beds),]
View (p1)
newmap<-leaflet(p1) %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.1))%>%
addCircles(lng = ~x, lat = ~y, weight = 2.5,
radius = ~(icu_beds*100), popup = ~facility)
newmap