#Used Google API key to restrict OVER_Query LIMIT
key <- "AIzaSyBROa5WcKppja2V9hFzRSm0zBLC8KAc0Aw"
google_geocode(address = "Pennsylvania", key = key)
## $results
## address_components
## 1 Pennsylvania, United States, PA, US, administrative_area_level_1, political, country, political
## formatted_address geometry.bounds.northeast.lat
## 1 Pennsylvania, USA 42.51607
## geometry.bounds.northeast.lng geometry.bounds.southwest.lat
## 1 -74.6895 39.7198
## geometry.bounds.southwest.lng geometry.location.lat
## 1 -80.51989 41.20332
## geometry.location.lng geometry.location_type
## 1 -77.19452 APPROXIMATE
## geometry.viewport.northeast.lat geometry.viewport.northeast.lng
## 1 42.51607 -74.6895
## geometry.viewport.southwest.lat geometry.viewport.southwest.lng
## 1 39.7198 -80.51989
## place_id types
## 1 ChIJieUyHiaALYgRPbQiUEchRsI administrative_area_level_1, political
##
## $status
## [1] "OK"
map <- get_map(location = "Pennsylvania", maptype = "roadmap",zoom = 7)
ggmap(map) + geom_point(aes(x, y, color=I("red"),size=3),alpha = 0.6, size = 2, data = Hospdata)
set.seed(1)
#Removing the missing attributes in BedSize
hospbedsize <- Hospdata[!(is.na(Hospdata$beds_sus) | Hospdata$beds_sus==""), ]
#Extractibg Hospitals with more than 100 Beds
bedsize100plus <- subset(hospbedsize, beds_sus>=100)
lat <- bedsize100plus$x
lon <- bedsize100plus$y
bedsize <- bedsize100plus$beds_sus
qmplot(x, y, data = bedsize100plus ) +
geom_point(aes(x=lat, y=lon, color = I('red'),size= bedsize,
alpha= 0.2)) +
ggtitle("Hospitals in Pennsylvania by Bed size")+
ylab("Latitude") + xlab("Longitude") +
theme(plot.title = element_text(hjust = 0.5, size = 15, vjust =1.4, face ="bold"))
##### From the above visualization we could determine that the most of the hospitals with bed capacity more than 100 are located in Philadelphia and Pittsburgh
hosptrauma <- Hospdata[complete.cases(Hospdata[,1]),]
TraumaAvailability <- hosptrauma$acc_trauma
lattrauma <- hosptrauma$x
lontrauma <- hosptrauma$y
qmplot(x, y, zoom=8, data =hosptrauma, colour = I('blue'))+
geom_point(aes(x = lattrauma, y = lontrauma, colour = TraumaAvailability))+
ggtitle("Pennsylvania Hospitals which are accredited trauma")
library(leaflet)
library(dplyr)
cardiachosp <- subset(Hospdata, cardiac == "Y")
cardiachospccity <- head(cardiachosp %>% group_by(city) %>% count()%>% arrange(desc(n)), 4)
cardiachospdata <- subset(cardiachosp, city %in% cardiachospccity$city)
insetMap <- leaflet() %>%
addTiles() %>%
setView(mean(cardiachospdata$x), mean(cardiachospdata$y), zoom = 6)
leaflet(width = "100%") %>% addTiles() %>%
setView(mean(cardiachospdata$x), mean(cardiachospdata$y), zoom = 7) %>%
addMarkers(cardiachospdata$x, cardiachospdata$y,
popup = cardiachospdata$facility,
label = cardiachospdata$facility,
labelOptions = labelOptions(direction = 'right', opacity = 0.9
)) %>%
addMiniMap(insetMap, position = "topright", width = 95, height = 95,
collapsedWidth = 18, collapsedHeight = 18, zoomLevelOffset = -4)