# Define marker colors based on whether a city serves as a capital
colors <- c(
"Non-capital" = "green",
"Capital" = "red"
)
fill_colors <- colors[(us_cities$capital > 0) + 1L] |>
as.character()
# Print map with city circle markers and a map legend
make_map(maps = "Topo") |>
leaflet::addCircleMarkers(
lng = ~lng,
lat = ~lat,
radius = 6,
color = "white",
weight = 1,
opacity = 1,
fillColor = fill_colors,
fillOpacity = 1,
fill = TRUE,
data = us_cities
) |>
add_legend(
labels = names(colors),
colors = colors,
radius = 5,
opacity = 1,
symbol = "circle"
)
Run the code above in your browser using DataLab