# Creating popup with all variables
popup_all <- paste0(
"<b>State: </b>", merged_data$LocationDesc, "<br>",
"<b>Obesity (%): </b>", round(merged_data$obesity, 1), "<br>",
"<b>Physical Inactivity (%): </b>", round(merged_data$inactivity, 1), "<br>",
"<b>Low Fruit Consumption (%): </b>", round(merged_data$fruit, 1), "<br>",
"<b>Low Vegetable Consumption (%): </b>", round(merged_data$veg, 1)
)
pal <- colorNumeric(
palette = c("#fde2e4", "#f4acb7", "#c9184a"),
domain = merged_data$obesity
)
# Creating the map
leaflet(data = merged_data) |>
setView(lng = -98, lat = 39, zoom = 4) |>
addProviderTiles("Esri.WorldStreetMap") |>
addCircles(
lng = ~lon,
lat = ~lat,
radius = ~obesity * 500,
color = ~pal(obesity),
fillColor = ~pal(obesity),
fillOpacity = 0.7,
popup = popup_all
) |>
addLegend(
position = "bottomright",
pal = pal,
values = merged_data$obesity,
title = "Obesity (%)",
opacity = 0.7
)