leaflet(data = data_2021) %>%
addTiles() %>%
addControl(
html = HTML("<b>Note:</b> Strong correlations are outlined in bold."),
position = "bottomright"
) %>%
addControl(
html = HTML("<b>Levels of cancer:</b>
<br> High >= 9%
<br> Medium >= 7% or < 9%
<br> Low < 7%
<br> <b>Levels of radon (pCi/L):</b>
<br> High >= 4
<br> Medium >= 1.3 or < 4
<br> Low < 1.3"),
position = "topright"
) %>%
addPolygons(
fillColor = ~pal(combined_category), # Use combined category for color
color = ~ifelse(combined_category %in% c("High Cancer High Radon", "Medium Cancer Medium Radon", "Low Cancer Low Radon"), "black", "gray"), # Bold outline for selected categories
weight = ~ifelse(combined_category %in% c("High Cancer High Radon", "Medium Cancer Medium Radon", "Low Cancer Low Radon"), 2, 1), # Thicker line for selected categories
fillOpacity = ~ifelse(combined_category %in% c("High Cancer High Radon", "Medium Cancer Medium Radon", "Low Cancer Low Radon"), 1, 1), # Thicker line for selected categories
popup = ~paste0(NAME, ": Cancer Rate = ", Cancer, ", Radon = ", Radon) # Popup with county details
) %>%
addLegend(
position = "bottomright",
pal = pal,
values = c("High Cancer High Radon", "High Cancer Medium Radon", "High Cancer Low Radon",
"Medium Cancer High Radon", "Medium Cancer Medium Radon", "Medium Cancer Low Radon",
"Low Cancer High Radon", "Low Cancer Medium Radon", "Low Cancer Low Radon"),
labels = c("<b>High Cancer High Radon</b>", "High Cancer Medium Radon", "High Cancer Low Radon",
"Medium Cancer High Radon", "<b>Medium Cancer Medium Radon</b>", "Medium Cancer Low Radon",
"Low Cancer High Radon", "Low Cancer Medium Radon", "<b>Low Cancer Low Radon</b>"),
labFormat = function(type, cuts, p) {
# Use HTML labels matching the palette
c("<b>High Cancer High Radon</b>", "High Cancer Medium Radon", "High Cancer Low Radon",
"Medium Cancer High Radon", "<b>Medium Cancer Medium Radon</b>", "Medium Cancer Low Radon",
"Low Cancer High Radon", "Low Cancer Medium Radon", "<b>Low Cancer Low Radon</b>")
},
title = "Cancer & Radon",
na.label = "No Data"
)