我有一个如下所示的数据框:
head(mydf)
id lat lon type
1 1 40.43859 -79.96828 2
2 2 40.58657 -79.76769 1
3 3 40.53450 -79.21241 2
4 4 40.41032 -79.86355 2
5 5 40.44095 -80.06801 2
6 6 40.35060 -79.85733 2
我正在使用传单进行这样的绘制,除了显示的图例外,它的工作正常:
library(leaflet)
factpal <- colorFactor(c('#FF7F0E', '#1F77B4', '#2CA02C', '#E41A1C'), mydf$type)
mydf %>% leaflet() %>%
setView(-95, 35, 4) %>% addProviderTiles("Stamen.TonerLite",
options = providerTileOptions(noWrap = TRUE)) %>%
addCircles(radius = 10, color = ~factpal(type)) %>%
addLegend(position = 'bottomright', pal = factpal, values = ~type, opacity = 1)
但是,图例不显示我的30K +行数据集。奇怪的是,当我对整个数据集采样较小的数据帧时,图例显示完美。我的代码或addLegend有什么问题?
这有效:
mydfSub <- mydf[sample(1:nrow(mydf), 1000), ]
mydfSub %>% leaflet() %>%
setView(-95, 35, 4) %>% addProviderTiles("Stamen.TonerLite",
options = providerTileOptions(noWrap = TRUE)) %>%
addCircles(radius = 10, color = ~factpal(type)) %>%
addLegend(position = 'bottomright', pal = factpal, values = ~type, opacity = 1)