使用传单和R为CircleMarkers添加边框

时间:2018-02-19 09:51:18

标签: r maps leaflet

我想为CircleMarkers添加边框。我使用了以下代码。我找不到任何向笔画添加黑色边框的功能。

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)) 

1 个答案:

答案 0 :(得分:3)

如果您的意思是要将黑色用于描边,则以下代码可以完成这项工作。我使用了传单包中的地震数据来进行演示。您希望使用fillColor填充标记并保存color以为笔划指定颜色。

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