Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding border to CircleMarkers with leaflet and R

Tags:

r

maps

leaflet

I would like to add border to the CircleMarkers. I used the following code. I can't find any function to add black border to the stroke.

pal <- colorNumeric(palette = 'RdYlBu', domain = city_results$ratio)

m <- leaflet() %>% 
     addTiles() %>% 
     setView(lng = median(city_results$long), 
             lat = median(mean(city_results$lat)), 
             zoom = 8) %>% 
     addProviderTiles(providers$CartoDB) %>% 
     addCircleMarkers(data = city_results, lng = ~long, lat = ~lat,
                     radius = ~(Socioeconomic_status_group),
                     color = ~pal(ratio),
                     stroke = TRUE, fillOpacity =  0,
                     popup = ~as.character(nameH),
                     label = ~as.character(round(corr_value,2)),
                     labelOptions = labelOptions(noHide = T, textOnly = TRUE)) 
like image 624
user6041789 Avatar asked Jan 28 '23 15:01

user6041789


1 Answers

If you mean that you want to use black color for stroke, the following code does the job. I used the earthquakes data from the leaflet package for this demonstration. You want to use fillColor to fill markers and save color to assign a color to strokes.

library(leaflet)

pal <- colorNumeric(palette = "Blues", domain = quakes$mag)

leaflet() %>% 
addProviderTiles("OpenStreetMap.Mapnik") %>%
addCircleMarkers(data = quakes,
                 radius = ~mag * 5,
                 color = "black",
                 fillColor = ~pal(mag),
                 stroke = TRUE, fillOpacity = 0.5)

enter image description here

like image 143
jazzurro Avatar answered Jan 31 '23 07:01

jazzurro