I'm using a defined color palette in my circle markers to show the category of each point on the map. The points that show up on the map are colored according to the palette but the palette does not correspond to the levels I used in the domain. They seem to be colored randomly.
The relevant bit is the colorfactor definition and the leaflet plot:
library(dplyr)
library(tidyverse)
library(leaflet)
library(sf)
library(shiny)
library(leafpop)
acc<-read.csv('acc.csv')
names(acc) <- tolower(names(acc))
pal <- colorFactor(c("red", "navy", "green"), domain = c("1. Fatal", "2. Serious", "3. Slight"))
acc <- acc %>%
st_as_sf(coords = c("easting", "northing"), crs = 27700) %>% st_transform('+proj=longlat +datum=WGS84') %>%
dplyr::mutate(lon = sf::st_coordinates(.)[,1],
lat = sf::st_coordinates(.)[,2])
output$test <- renderLeaflet({
acc %>%
filter(local_auth %in% input$box_local_auth) %>%
filter(month %in% input$box_month) %>%
filter(year %in% input$box_year) %>%
filter(severity %in% input$box_severity) %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(
radius = 5,
color = ~pal(severity),
label = acc$severity,
popup=popupTable(popup)) %>%
addPolylines(data = map %>%
filter(LAD23NM %in% input$box_local_auth), color = "blue",fillOpacity = 0)
These images show the colors not following any logic: