Is there a way to color a site on a leaflet addCircleMarkers() map based on values from a list / the first value from a list / look for a specific value from a list? etc etc
This is an example of data structure I'm working with, where we may encounter a site with duel purposes, and I've been trying to develop a method to show it on a map within R. Ideally, we don't want to change the data structure and this is a very watered down sample (e.g., can't add a value of "farm, house" = "green").
This sample code used the colorfactor from leaflet to assign predetermined colors based on a value. On the 3rd case in this sample data, I need that 3rd sit to either turn "blue" for farm, or "red for house (depends on the kind of filter I'll develop later on to search for sites with specific values).
###################################################################################
###################################################################################
# Libraries
library(dplyr)
library(leaflet)
###################################################################################
###################################################################################
# InputData & Functions
Map_DF <- data.frame("Point_ID" = 1:3,
"Latitude" = c(38.10, 38.20, 38.30),
"Longitude" = c(-107.10, -107.20, -107.30),
"PointUse" = c("farm", "house", "farm, house"))
PointUsePalette <- colorFactor(palette = c("blue", "red"),
domain = c("farm", "house"))
###################################################################################
###################################################################################
# Leaflet Map
leaflet() %>%
addProviderTiles(
providers$CartoDB.Positron
) %>%
setView(
lng = -107.20,
lat = 38.20,
zoom = 11
) %>%
addCircleMarkers(
data = Map_DF,
lat = ~Latitude,
lng = ~Longitude,
radius = 5,
color = ~PointUsePalette(PointUse),
popup = ~PointUse
)