Create a series of 5 maps that highlight spatial differences in hospital service coverage for the state of PA.
To understand the distribution of the hospitals in PA, the following graph was plotted by the bed size.
library(ggmap)
## Removing the rows where bedsize was not defined
pa_hospital_data2_bedsize <- pa_hospital_data2[complete.cases(pa_hospital_data2[,11]),]
## Renaming the columns for undestandibility
latitude <- round(pa_hospital_data2_bedsize$x,2)
longitude <- round(pa_hospital_data2_bedsize$y,2)
BedSize <- pa_hospital_data2_bedsize$beds_sus
## Scatterplot of PA hospitals by bed size
plot_pa_hosp <- qmplot(x, y, data = pa_hospital_data2_bedsize ) +
geom_point(aes(x = latitude, y = longitude, size = BedSize,
color = BedSize, alpha= 1.0)) +
ggtitle("Distibution of Pennsylvania Hospitals by Size")+
ylab("Latitude") + xlab("Longitude") +
theme(plot.title = element_text(hjust = 0.5, size = 15, vjust =1.4, face ="bold"))
plot_pa_hosp + scale_alpha(guide = 'none') + guides(size=FALSE)
From the above graph, it is evident that Philadelphia followed by Pittsburg has the highest concentration of hospitals by bedsize in the state of PA.
To compare the distibution of the hospitals across the state of PA, density plot was plotted to give a fuller picture for the true shape of the distribution and its density over geographical map.
library(ggmap)
## Getting the map of PA
ggmap_pa <- ggmap(get_map("Pennsylvaniia", zoom = 7), extent = "device")
## GGplot for density of hospitals in PA
ggmap_pa +
stat_density2d(
aes(x = x, y = y, fill = ..level..), alpha =0.8,
bins = 4, geom = "polygon",
data = pa_hospital_data2) +
labs(fill = "Hospital Density", title = "Density of Hospitals in Pennsylvania") +
theme( legend.position = "right", plot.title=element_text(size=rel(1.4), face="bold", hjust=0.5))
From the above graph, it is very clear that the density of the hospital in and around the city of Philadelphia and Pittsburg is very high with roughly 30% of hospitals around Philadelphia and 25% around Pittsburg area.
To understand the different kind of services that the hospitals in the state of PA perform, I chose to look at Philadelphia, the region that had the highest dense concentration of hospitals. I further chose to look for hospitals that offer Chemotherapy because it helps cancer patients which is a very critical disease in humans.
library(leaflet)
library(dplyr)
## Filter the dataset to include hospitals offerring Chemotherapy
chemotherapy = subset(pa_hospital_data2, chemo == "Y")
## Filter the dataset to include hospitals offerring Chemotherapy in Philadelphia
pa_chemo_facility = subset(chemotherapy, county == "Philadelphia")
## Generating leaflet plot
leaflet(pa_chemo_facility, width = "100%") %>% addTiles() %>%addProviderTiles(providers$MtbMap) %>%
addProviderTiles(providers$Stamen.TonerLines,
options = providerTileOptions(opacity = 0.40)) %>%
addProviderTiles(providers$Stamen.TonerLabels) %>%
addCircleMarkers(~x, ~y, popup = ~as.character(facility), label = ~as.character(facility), color="red")
From the above graph, we observe that most hospitals offering chemotheraphy are agglomerated in the northern and western parts of Philadelphia county.
To understand the different kind of services that the hospitals in the state of PA perform, I chose to look at the top two cities with higest number of Cardiac facilities, i.e., Philadelphia and Pittsburg. I further chose to look for hospitals that offer cardiac facilities because it assists patients with heart diseaes which has been seen to increase considerably as the time is progressing to compensate for survival of the fittest goal in today’s rat race.
library(leaflet)
library(dplyr)
## Filter the dataset to include hospitals offerring cardiac services
cardiac_facility = subset(pa_hospital_data2, cardiac == "Y")
## Filter the dataset to include top two cities with high density of hospitals in PA offerring cardiac services
pa_cities_cadriac_facility <- head(cardiac_facility %>%
group_by(city) %>% count()%>%
arrange(desc(n)), 2)
## Subset the cardiac services dataset for only the top two cities
pa_cardiac_facility_df <- subset(cardiac_facility, city %in% pa_cities_cadriac_facility$city)
## Setting the color theme
getColor <- function(pa_cardiac_facility_df) {
sapply(pa_cardiac_facility_df$city, function(city) {
if(city == "Philadelphia") {
"green"
} else {
"red"
} })
}
## Custom icon
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = getColor(pa_cardiac_facility_df)
)
## Leaflet plot for the cardiac sevices
leaflet(width = "100%") %>% addTiles() %>%
setView(mean(pa_cardiac_facility_df$x), mean(pa_cardiac_facility_df$y), zoom = 7) %>%
addAwesomeMarkers(data = pa_cardiac_facility_df, ~x, ~y, icon =icons,
popup = paste(pa_cardiac_facility_df$facility, "<br>",
"Bed Size:", pa_cardiac_facility_df$beds_sus, "<br>",
"Services Provided:", pa_cardiac_facility_df$typ_serv),
label = paste(pa_cardiac_facility_df$facility,";",
"Bed Size:", pa_cardiac_facility_df$beds_sus, ";",
"Services Provided:", pa_cardiac_facility_df$typ_serv),
labelOptions = labelOptions(direction = 'right', opacity = 0.9
))
In the above graph, we can zoom in and out to view the hospitals offering cardiac services with the facility name, bedsize and the type of services performed by each in the city of Philadelphia and Pittsburg. Philadelphia has about 9 hospitals and Pittsbug has 7 hospitals which is approximately 20 percent and 16 percent respectively of total hospitals in Philadelphia city providing cardiac facilities.
Since Pharmacies play an equally important role in the well bng of the patients, I chose to look at the top five cities with high frequency of pharmacies, i.e., Philadelphia, Pittsburg, Erie, Allentown followed by Wilkes-Barre.
library(leaflet)
library(dplyr)
## Filter the dataset to include cities having Pharmacy
pharmacy = subset(pa_hospital_data2, pharmacy == "Y")
## Filter the dataset to include top five cities with high density of pharmacies in PA
pharmacy_facility_cities<- head(pharmacy %>% group_by(city) %>% count() %>% arrange(desc(n)), 5)
## Subset the pharmacy dataset for only the top five cities
pa_pharmacy_facility_df_ph <- subset(pharmacy, city %in% pharmacy_facility_cities$city[1])
pa_pharmacy_facility_df_pb <- subset(pharmacy, city %in% pharmacy_facility_cities$city[2])
pa_pharmacy_facility_df_er <- subset(pharmacy, city %in% pharmacy_facility_cities$city[3])
pa_pharmacy_facility_df_at <- subset(pharmacy, city %in% pharmacy_facility_cities$city[4])
pa_pharmacy_facility_df_wb <- subset(pharmacy, city %in% pharmacy_facility_cities$city[5])
## Leafet plot for the pharmacy dataset
leaflet(width = "100%") %>% addTiles() %>% addProviderTiles(providers$OpenStreetMap) %>%
addMarkers(data = pa_pharmacy_facility_df_ph, lng = ~x, lat = ~y,
group = "Philadelphia",
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F))%>%
addMarkers(data = pa_pharmacy_facility_df_pb, lng = ~x, lat = ~y,
group = "Pittsburg",
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F))%>%
addMarkers(data = pa_pharmacy_facility_df_er, lng = ~x, lat = ~y,
group = "Erie",
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F))%>%
addMarkers(data = pa_pharmacy_facility_df_at, lng = ~x, lat = ~y,
group = "Allentown",
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F))%>%
addMarkers(data = pa_pharmacy_facility_df_wb, lng = ~x, lat = ~y,
group = "Wilkes-Barre",
clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F))%>%
addLayersControl(
overlayGroups = c("Philadelphia", "Pittsburg","Erie","Allentown","Wilkes-Barre"),
options = layersControlOptions(collapsed = FALSE))
The above graph helps us to locate the Pharmacies in the state of PA. The pharmacies are arranged in the order of top 5 cities with maximum number of Pharmacies with Philadelphia having approximately 13 percent followed by Pittsburg at 9 percent as againt the total number of the Pharmacies in PA.
Surgery plays a fundamental role to avert the death and chronic disability and several other conditions that can have a significant impact on the quality of life. I therfore chose to look at the top ten cities providing maximmum number of surgical services in the state of PA.
library(leaflet)
library(dplyr)
## Filter the dataset to include cities having surgical services
surgical_facility = subset(pa_hospital_data2, surgical_s == "Y")
## Filter the dataset to include top ten cities with high density of surgical services in PA
surgical_facility_cities<- head(surgical_facility %>% group_by(city) %>%
count() %>% arrange(desc(n)), 10)
## Subset the pharmacy dataset for only the top ten cities
surgical_facility_df <- subset(surgical_facility, city %in% surgical_facility_cities$city)
## Inset map
insetMap <- leaflet() %>%
addTiles() %>%
setView(mean(surgical_facility_df$x), mean(surgical_facility_df$y), zoom = 6)
## Custom Icon for surgical services
surgicalIcon <- makeIcon(
iconUrl = "http://ahjuice.com/wp-content/uploads/leaflet-maps-marker-icons/hospital-2.png",
iconWidth = 30*213/220, iconHeight = 30,
iconAnchorX = 30*213/220/2, iconAnchorY = 15
)
## Leaflet for surgical services
leaflet(surgical_facility_df, width = "100%") %>% addTiles() %>%
addMarkers(lng = ~x, lat = ~y, icon = surgicalIcon, popup = ~as.character(facility), label = ~as.character(facility)) %>%
addMiniMap(insetMap, position = "topright", width = 95, height = 95,
collapsedWidth = 18, collapsedHeight = 18, zoomLevelOffset = -4)
In above graph, we can observe the distribution of hospitals that have surgical facilities in the state of PA for the top ten cities with higest concentration of hospitals. It is evident that the city of Philadelphia and Pittsburg lead other cities having 20 and 14 surgical facilities respectively.
Data visualization is an art of visualizing hetrogeneous data by asthetically pleasing visuals to easily determine patterns which might otherwise get unnoticed in data sources like spreadsheets thereby assisting in informatiive, appealing, efficient, interactive and predective decision making and significantly cutting down the analysis time.
Leaflet is one of the most poweful data vizualiztion tool that help a user build elegant maps with several control and rendering features for visualizing geospatial data.Leaflets have no limit on how creative one can get with its design capabilities. Inctricacies can be clearly defined. Further, a lot more information can be included with high level of interactivity.