1/30/2021

Coursera Developing Data Project Description

During the Developing Data Products course, our projects have been focused on creating interactive aids to dynamically visualize information.

My efforts have been focused on indirectly following the effects of COVID 19 in the United States by following the number of beds in use at various kinds of hospitals.The two types of beds I focused on during the course were staffed beds and licensed beds

-Staffed Beds; An “adult bed, pediatric bed, birthing room, or newborn ICU bed (excluding newborn bassinets) maintained in a patient care area for lodging patients in acute, long term, or domiciliary areas of the hospital.”

-Licensed Beds; The maximum number of beds for which a hospital holds a license to operate; however, many hospitals do not operate all the beds for which they are licensed.

All figures were collect by Definitive Health Care, hosted on ESRI’s Coronavirus-Resources, https://coronavirus-resources.esri.com/search. The raw data can be downloaded with this link; https://opendata.arcgis.com/datasets/1044bb19da8d4dbfb6a96eb1b4ebf629_0.csv

Developing the Map

Leaflet provides a easy way to adapt geospatial data into an interactive format for the user to manipulate.The following code draws a leaflet map of hospitals in the United States from URL that is peroidically updated

library(leaflet)

#Call Data From Directory
hosp_data <- read.csv("hospital_data.csv", header = TRUE)
#Complete empty data
hosp_data <- hosp_data[complete.cases(hosp_data), ]

#Assign Latitude
hosp_lat <- as.vector(hosp_data$Y)
#Assign Longitude
hosp_lng <- as.vector(hosp_data$X)
#Assign Names
hosp_names <- as.vector(hosp_data$HOSPITAL_NAME)
#Asign Color Palette based on Hospitial_TYPE
pal <- colorFactor(palette = 'Paired', domain = hosp_data$HOSPITAL_TYPE)

#Draw Leaflet Map
hosp_map <- leaflet(hosp_data)%>%
addTiles(urlTemplate = "http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png", 
       attribution = '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>')%>%
addCircleMarkers(lng = ~X, lat = ~Y, radius = 2, color = ~pal(HOSPITAL_TYPE), popup = paste("Name;", 
hosp_data$HOSPITAL_NAME, "<br>", "Type; ", hosp_data$HOSPITAL_TYPE, "<br>", "Beds; ", hosp_data$NUM_STAFFED_BEDS))
hosp_map

Developing the plot

Plotly provides an efficient way to visualize the data in as a variety of different plots with a great deal of customization. The following code draws a plotly scatter plot of hospitals in the New England Region of the United States from URL that is peroidically updated

#Pull Data from Directory
hosp_data <- read.csv("hospital_data.csv", header = TRUE)
#Complete empty Data
hosp_data <- hosp_data[complete.cases(hosp_data), ]

#Develop List of States in New England
new_england <- c("Connecticut", "Massachusetts", "Vermont", "New Hampshire", "Maine", "Rhode Islannd")
new_england_hosp <- hosp_data[hosp_data$STATE_NAME %in% new_england ,]

#Draw Plotly Scatter Plot using Staffed and Licensed Beds for each Axis
new_england_hosp_plot <- plot_ly(data = new_england_hosp, type = 'scatter', x = ~NUM_LICENSED_BEDS, y = ~NUM_STAFFED_BEDS, 
color = ~HOSPITAL_TYPE, colors = "Paired", mode = 'markers', size = 5, 
text = ~paste('State: ', STATE_NAME, '</br> Hospital Name: ', HOSPITAL_NAME, '</br> Staffed Beds: ', 
NUM_STAFFED_BEDS, '</br> Licensed Beds: ', NUM_LICENSED_BEDS))

new_england_hosp_plot <- new_england_hosp_plot %>% layout(title = 'Hospitals in the New England Region', 
xaxis = list(title = 'Number of Licensed Beds', zeroline = TRUE), yaxis = list(title = 'Number of Staffed Beds'))
new_england_hosp_plot

Hospital Plot

R Shiny Web Application

R Shiny provides the proper platform to easily host the reportings and applications. For this project, a simple “ui” code was developed incorporating the key elements of a title, sidebar panel with a dropdown box of the states, and a main panel displaying both the leaflet map and plotly scatter plot.

Inside the ‘server’ the use of ‘updateSelectizeInput’ function and leafletProxy and plotlyProxy allow the user to update the map and scatter plot based off their input. When a new state is selected from the dropdown menu, the map and scatter plot will both auto update to reflect the most recent selection.

The final R Shiny application can be found at this link; https://jmastapeter.shinyapps.io/peer_graded_assignment_hospitals/

The server and ui codes along with the raw hospital data can be found at this github repository; https://github.com/jmastapeter/Developing_Data_Products_Assigment_IV