---
title: "Uninsured Analysis"
output:
flexdashboard::flex_dashboard:
theme: yeti
orientation: rows
vertical_layout: scroll
logo: data/mhbelogo.png
social: menu
source: embed
includes:
after_body: footer.html
bibliography: citations.bib
runtime: shiny
---
```{r setup, include=FALSE}
library(ipumsr) # import ACS microdata from IPUMS.org
library(acs) # useful functions for working w/ ACS data
library(tidyverse) # many useful syntax and QOL functions
library(labelled) # labels variables/values
library(janitor) # cleans up column names
library(stringr) # for working with strings
library(knitr) # for RMarkdown to HTML
library(rmarkdown) # to generate Rmd final document
library(flexdashboard) # to generate Rmd dashboard
library(sf) # simple features for mapping
library(leaflet) # creates interactive maps
#library(mapview) # saves the image of the map for exporting
#library(mapedit) # more map tools
library("esri2sf") # import ESRI ArcGIS maps as shapefiles
library(tigris) # import TIGRIS shapefile data
library(htmlwidgets) # export leaflet maps to HTML
library(DT) # display HTML tables from dataframes/matrices
library(shiny) # dashboard interactivity
library(plotly) # interactive ggplots
#library(bsplus) # bootstrap markup objects library
library(htmltools)
# read in data
acs_df <- readRDS("data/processed/acs_df.Rds")
puma.sf <- readRDS("data/processed/puma-sf.Rds")
df.summary <- readRDS("data/processed/df-summary.Rds")
cnty.sf <- readRDS("data/processed/cnty-sf.Rds")
unins.age.plot <- readRDS("data/processed/unins-age-plot.Rds")
esi.age.plot <- readRDS("data/processed/esi-age-plot.Rds")
unins.race.plot <- readRDS("data/processed/unins-race-plot.Rds")
esi.race.plot <- readRDS("data/processed/esi-race-plot.Rds")
df.unins.pop <- readRDS("data/processed/df-unins-pop.Rds")
df.summ.unfilt <- readRDS("data/processed/df-summ-unfilt.Rds")
df.ind.esi.loss <- readRDS("data/processed/df-ind-esi-loss.Rds")
df <- readRDS("data/processed/df.Rds")
df.unins.pop.state.filt <- readRDS("data/processed/df-unins-pop-state-filt.Rds")
df.unins.pop.filt <- readRDS("data/processed/df-unins-pop-filt.Rds")
age.fpl.plot <- readRDS("data/processed/age-fpl-plot.Rds")
post.esi.race.plot <- readRDS("data/processed/post-esi-race-plot.Rds")
post.unins.age.plot <- readRDS("data/processed/post_unins-age-plot.Rds")
post.esi.age.plot <- readRDS("data/processed/post-esi-age-plot.Rds")
post.unins.race.plot <- readRDS("data/processed/post-unins-race-plot.Rds")
post.age.fpl.plot <- readRDS("data/processed/post-age-fpl-plot.Rds")
df.esi.loss.state.unfilt <- readRDS("data/processed/df-esi-loss-state-unfilt.Rds")
df.elig.pre <- readRDS("data/processed/df-elig-pre.Rds")
df.elig.post <- readRDS("data/processed/df-elig-post.Rds")
```
Sidebar {.sidebar}
=====================================
* An estimated 357,000 Marylanders lacked health coverage at the end of 2019.
* Of this group, an estimated 200,000 individuals were eligible for Medicaid or financial help with private health insurance plans.
* Young adults aged 19-34 are the most likely to be uninsured. An estimated 11% of young adults in this range lack coverage but are eligible to enroll through Maryland Health Connection.
* Between March and August 2020, an estimated 112,000 Marylanders lost a job that provided health insurance.
* Of this group, an estimated 65,000 individuals became uninsured due to COVID related job loss.
2018/19 Uninsured {data-icon="fa-map-marked"}
=====================================
## Row 1
-------------------------------------
### Total Uninsured {.value-box data-height=50}
```{r}
# # number of uninsured who are lawfully present and not institutionalized (352,265)
# unins.state <- acs_df_state %>% summarize(uninsured = sum(ifelse(hcovany==1 & relate != 13,
# perwt, 0)))
# unins.input <- format(unins.state$uninsured, big.mark = ",", trim=TRUE)
# valueBox(value = unins.input)
# Alternative values obtained from Census report HI_05 (357,000 uninsured):
# https://www.census.gov/data/tables/time-series/demo/health-insurance/acs-hi.html
valueBox("357,000")
```
### Uninsured, MHC Eligible {.value-box data-height=50}
```{r}
# number of uninsured who are lawfully present and not institutionalized (251,064)
# unins.state.filt <- acs_df_state %>% summarize(uninsured = sum(ifelse(hcovany==1 & lawful==1 & relate != 13,
# perwt, 0)))
# unins.input.filt <- format(unins.state.filt$uninsured, big.mark = ",", trim=TRUE)
# valueBox(unins.input.filt)
# Alternative values obtained from Census report HI_05 (357,000 uninsured):
# https://www.census.gov/data/tables/time-series/demo/health-insurance/acs-hi.html
# Adjusted for unauthorized migrants using CMSNY data tool total of uninsured
# unauthorized, 98,999
valueBox("258,000")
```
### Total Insured {.value-box data-height=50}
```{r}
# any insurance (5,624,736)
# ins.state <- acs_df_state %>% summarize(insured = sum(ifelse(hcovany==2 & relate != 13,
# perwt, 0)))
# ins.input <- format(ins.state$insured, big.mark = ",", trim=TRUE)
# valueBox(ins.input, color = "success")
# Alternative values obtained from Census report HI_05 (5,589,000 any insurance):
# https://www.census.gov/data/tables/time-series/demo/health-insurance/acs-hi.html
valueBox("5,589,000", color = "success")
```
### Insured Through Employer {.value-box data-height=50}
```{r}
# employer-sponsored insurance (3,774,936)
# esi.state <- acs_df_state %>% summarize(esi = sum(ifelse(hinsemp==2 & relate != 13,
# perwt, 0)))
# esi.input <- format(esi.state$esi, big.mark = ",", trim=TRUE)
# valueBox(esi.input, color = "success")
# Alternative values obtained from Census report HI_05 (3,753,000 emp insurance):
# https://www.census.gov/data/tables/time-series/demo/health-insurance/acs-hi.html
valueBox("3,753,000", color = "success")
```
### Total Percent Uninsured {.value-box data-height=50}
```{r}
# percent uninsured of non-institutionalized population, calculated from ACS
# 2018 1-year IPUMS microdata (5.89%)
# pct.unins.state.filt <- acs_df_state %>% summarize(pct_unins = (sum(ifelse(hcovany==1 & relate != 13, perwt, 0)))/(sum(ifelse(relate != 13, perwt, 0))))
# pct.unins.input <- pct.unins.state.filt$pct_unins
# valueBox(paste0(round(pct.unins.input,4)*100,"%"))
# Alternative values obtained from Census report HI_05:
# https://www.census.gov/data/tables/time-series/demo/health-insurance/acs-hi.html
valueBox("6.0%")
```
## Row 2 {data-height=600 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Total Uninsured
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.summ.unfilt, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 3000:35000)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Uninsured: ",
format(round(joined$uninsured,0), big.mark = ",", trim=TRUE))
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(uninsured),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$uninsured, position = "bottomright",
title = "Total Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE))
```
### Eligible Uninsured
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.summary, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 3000:16000)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Uninsured: ",
format(round(joined$uninsured,0), big.mark = ",", trim=TRUE))
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(uninsured),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$uninsured, position = "bottomright",
title = "Eligible Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Uninsured Rates
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.summary, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 0:13)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Percent Uninsured: ",
round((joined$pct_uninsured)*100,2), "%")
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(pct_uninsured*100),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$pct_uninsured*100, position = "bottomright",
title = "Percent Eligible Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Uninsured by County
```{r}
# read in PUMA to County crosswalk
geocorrP2C <- read_csv("data/raw/geocorr2018.csv")
geocorrP2C <- geocorrP2C[-1,]
geocorrP2C <- geocorrP2C %>% mutate(puma = sprintf("%05d", as.numeric(puma12)))
# join crosswalk to unins df by ZIP
map3 <- left_join(df.summary, geocorrP2C, by = "puma")
# calculate unins per PUMA using allocation factor
map3 <- map3 %>% mutate(unins.cnty = uninsured*as.numeric(afact))
# aggregate up to puma level, summing the allocated claims
cnty.map.unins <- map3 %>% group_by(county) %>%
summarise(uninsured.cnty = sum(unins.cnty, na.rm = TRUE))
# join shapefile to data
joined.cnty <- ipums_shape_inner_join(cnty.map.unins, cnty.sf, by=c("county"="GEOID"))
# define palette and popups
bins <- c(0,1000,5000,10000,20000,30000,40000,50000,60000)
pal <- colorBin(palette = "YlGnBu", domain = joined.cnty$uninsured.cnty, bins = bins)
popup <- paste0("Area: ", joined.cnty$NAMELSAD, "
", "Uninsured: ",
format(round(joined.cnty$uninsured.cnty,0), big.mark = ",", trim=TRUE))
leaflet(joined.cnty, height = 400) %>%
addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
addPolygons(data=joined.cnty, fillColor = ~pal(uninsured.cnty),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.6, weight = 1,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
smoothFactor = 0.2, popup = ~popup, label = joined.cnty$NAMELSAD) %>%
addLegend("bottomright", pal = pal, values = ~uninsured.cnty,
title = "Eligible Uninsured by County") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Demographic Breakdowns
```{r}
fillRow(
fillCol(ggplotly(unins.age.plot, self_contained = FALSE) %>% layout(legend = list(yanchor = "center")),
ggplotly(esi.age.plot, self_contained = FALSE) %>% layout(legend = list(yanchor = "center"))),
fillCol(ggplotly(unins.race.plot, self_contained = FALSE) %>% layout(legend = list(yanchor = "center")),
ggplotly(esi.race.plot, self_contained = FALSE) %>% layout(legend = list(yanchor = "center"))),
flex = c(1,1.5))
```
### Uninsured by Age & FPL
```{r, fig.width=10,fig.height=11}
ggplotly(age.fpl.plot, self_contained = FALSE) %>%
layout(title ="Uninsured, MHC Eligible by Age Group and Percent of the Federal Poverty Level")
```
### Eligibility Breakdowns
```{r}
sketch = withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, style = 'border-right: solid 2px;','Public Use Microdata Area'),
th(colspan = 4, style = 'border-right: solid 2px;', 'Eligible for Financial Assistance'),
th(colspan = 3, style = 'border-right: solid 2px;', 'Ineligible for Financial Assistance')
),
tr(
th(colspan = 1, 'Adults - QHP Subsidy Eligible'),
th(colspan = 1, 'Adults - Medicaid Eligible'),
th(colspan = 1, 'Children - QHP Subsidy or Medicaid Eligible'),
th(colspan = 1, style = 'border-right: solid 2px;', 'Total'),
th(colspan = 1, 'Income over 400% FPL'),
th(colspan = 1, 'Offer of Employer-Sponsored Insurance'),
th(colspan = 1, style = 'border-right: solid 2px;', 'Total')
)
)
))
#fillRow(
datatable(df.elig.pre, container=sketch, rownames=FALSE, extensions = 'Buttons',
options = list(pageLength = 20, scrollY = "310px", dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')), caption = htmltools::tags$caption("Maryland Health Connection Eligible uninsured population, broken down by potential eligibility for financial assistance through qualified health plans (QHP) or Medicaid (MA).", style="font-size:150%")) %>%
formatStyle(c(1,5,8), `border-right` = "solid 2px")
#)
```
## Row 3
-------------------------
>"The Uninsured, MHC Eligible" and "Eligible Uninsured" estimates exclude undocumented immigrants because they are not eligible to enroll in coverage through Maryland Health Connection (MHC). Statewide estimates include some best-estimate assumptions not applied at the sub-state level. See Methodology for detail.
Potential COVID Impact {data-icon="fa-map-marked-alt"}
=====================================
## Row 1
-------------------------------------
### Total Uninsured {.value-box data-height=50}
```{r}
# number of uninsured (not institutionalized) if everyone who lost ESI becomes
# uninsured and including unauthorized individuals
unins.state.post <- df.esi.loss.state.unfilt$new_unins
unins.post.input.worst <- format(round(unins.state.post,0), big.mark = ",", trim=TRUE)
valueBox(unins.post.input.worst)
```
### Uninsured, MHC Eligible {.value-box data-height=50}
```{r}
# number of uninsured who are lawfully present and not institutionalized if
# only those ineligible for subsidized QHP or Medicaid become uninsured
unins.post.input <- df.unins.pop.state.filt$new_unins
unins.post.input <- format(round(unins.post.input,0), big.mark = ",", trim=TRUE)
valueBox(unins.post.input)
```
### Total Insured {.value-box data-height=50}
```{r}
ins.input.post <- format(round(df.esi.loss.state.unfilt$new_insured,0), big.mark = ",", trim=TRUE)
valueBox(ins.input.post, color = "success")
```
### Insured Through Employer {.value-box data-height=50}
```{r}
# new ESI figure, plus the 35% of those who lost ESi who enroll via their spouse
esi.input.post <- format(round(df.esi.loss.state.unfilt$new_ins_emp,0), big.mark = ",", trim=TRUE)
valueBox(esi.input.post, color = "success")
```
### Total Percent Uninsured {.value-box data-height=50}
```{r}
# percent uninsured non-institutionalized population
pct.unins.input.post <- df.esi.loss.state.unfilt$new_pct_unins
valueBox(paste0(round(pct.unins.input.post,3)*100,"%"))
```
## Row 2 {data-height=600 .tabset .tabset-fade}
-----------------------------------------------------------------------
### Total Uninsured
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.unins.pop, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 3000:35000)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Uninsured: ",
format(round(joined$new_unins,0), big.mark = ",", trim=TRUE))
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(new_unins),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$new_unins, position = "bottomright",
title = "Total Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Eligible Uninsured
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.unins.pop.filt, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 3000:12000)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Uninsured: ",
format(round(joined$new_unins,0), big.mark = ",", trim=TRUE))
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(new_unins),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$new_unins, position = "bottomright",
title = "Eligible Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Uninsured Rates
```{r}
# join data to shapefile by puma
joined <- ipums_shape_inner_join(df.unins.pop.filt, puma.sf, by=c("puma"="PUMACE10"))
# define palette to use, use range of uninsured values for scale of colors
pal <- colorNumeric(palette = "YlGnBu", domain = 0:10)
# create simple popup with PUMA name and total uninsured estimate
popup <- paste0("Area: ", joined$NAMELSAD10, "
", "Percent Uninsured: ",
round((joined$new_pct_unins)*100,2), "%")
# generate leaflet object, define basemap
leaflet(height = 400) %>% addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
# add shapes for uninsured totals, define color fill palette
addPolygons(data=joined, fillColor = ~pal(new_pct_unins*100),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.7, weight = 1,
# white outline on hover or click
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
# smooth out shapes for better performance, define popup params
smoothFactor = 0.2, popup = popup, label = joined$NAMELSAD10
) %>%
# add simple legend with color scale and labels in bottom right corner
addLegend(pal = pal, values = joined$new_pct_unins*100, position = "bottomright",
title = "Percent Eligible Uninsured by PUMA") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Uninsured by County
```{r}
# join crosswalk to unins df by ZIP
map3 <- left_join(df.unins.pop.filt, geocorrP2C, by = "puma")
# calculate unins per PUMA using allocation factor
map3 <- map3 %>% mutate(unins.cnty = new_unins*as.numeric(afact))
# aggregate up to puma level, summing the allocated claims
cnty.map.unins <- map3 %>% group_by(county) %>%
summarise(uninsured.cnty = sum(unins.cnty, na.rm = TRUE))
# join shapefile to data
joined.cnty <- ipums_shape_inner_join(cnty.map.unins, cnty.sf, by=c("county"="GEOID"))
# define palette and popups
bins <- c(0,1000,5000,10000,20000,40000,60000,80000)
pal <- colorBin(palette = "YlGnBu", domain = joined.cnty$uninsured.cnty, bins = bins)
popup <- paste0("Area: ", joined.cnty$NAMELSAD, "
", "Uninsured: ",
format(round(joined.cnty$uninsured.cnty,0), big.mark = ",", trim=TRUE))
leaflet(joined.cnty, height = 400) %>%
addProviderTiles("CartoDB.Positron", group = "CartoDB (Default)") %>%
addProviderTiles("Esri.WorldStreetMap", group = "Esri") %>%
addProviderTiles("CartoDB.DarkMatter", group = "CartoDB Dark") %>%
addPolygons(data=joined.cnty, fillColor = ~pal(uninsured.cnty),
# outline color, fill opacity, outline weight
color = "#444444", fillOpacity = 0.6, weight = 1,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE),
smoothFactor = 0.2, popup = ~popup, label = joined.cnty$NAMELSAD) %>%
addLegend("bottomright", pal = pal, values = ~uninsured.cnty,
title = "Eligible Uninsured by County") %>%
addLayersControl(
baseGroups = c("CartoDB (Default)", "Esri", "CartoDB Dark"),
options = layersControlOptions(collapsed = FALSE)
)
```
### Demographic Breakdowns
```{r}
fillRow(
fillCol(ggplotly(post.unins.age.plot, self_contained = FALSE), ggplotly(post.esi.age.plot, self_contained = FALSE)), fillCol(ggplotly(post.unins.race.plot, self_contained = FALSE), ggplotly(post.esi.race.plot, self_contained = FALSE) ),
flex = c(1,1.5))
```
### Uninsured by Age & FPL
```{r}
ggplotly(post.age.fpl.plot, self_contained = FALSE) %>%
layout(title ="Potential Uninsured, MHC Eligible by Age Group and Percent FPL")
```
### Eligibility Breakdowns
```{r}
sketch = withTags(table(
class = 'display',
thead(
tr(
th(rowspan = 2, style = 'border-right: solid 2px;','Public Use Microdata Area'),
th(colspan = 4, style = 'border-right: solid 2px;', 'Eligible for Financial Assistance'),
th(colspan = 3, style = 'border-right: solid 2px;', 'Ineligible for Financial Assistance')
),
tr(
th(colspan = 1, 'Adults - QHP Subsidy Eligible'),
th(colspan = 1, 'Adults - Medicaid Eligible'),
th(colspan = 1, 'Children - QHP Subsidy or Medicaid Eligible'),
th(colspan = 1, style = 'border-right: solid 2px;', 'Total'),
th(colspan = 1, 'Income over 400% FPL'),
th(colspan = 1, 'Offer of Employer-Sponsored Insurance **'),
th(colspan = 1, style = 'border-right: solid 2px;', 'Total')
)
)
))
js <- c(
"function(settings){",
" var datatable = settings.oInstance.api();",
" var table = datatable.table().node();",
" var caption = '** Estimated number of uninsured with offers of ESI remains unchanged as we cannot estimate the number of newly uninsured due to COVID job loss who could get ESI from their spouse or second jobs.', style = 'caption-side: bottom; text-align: center; color:grey; font-size:100% ;'",
" $(table).append('