我试图寻找一个答案,这个问题和碰到这个传来:显示自然的休息间隔
Manually adding legend values in leaflet
但是,这并不完全是我想为单张地图显示不过,我想,当我尝试用朋友加入他们的传说休息=我得到
我已经使用了ClassInt包R中找到詹克斯在我的数据自然断裂如下错误:
[0,3] (3,8] (8,16] (16,32] (32,70]
759 505 290 138 29
,然后用findColours来和RcolourBrewer包:
cols_code <- findColours(cols_classes, brewer.pal(5,"YlGnBu"))
当我使用这在我的单张地图,它工作正常,并通过多边形主题显示的颜色,因为我想:
leaflet() %>%
addProviderTiles("CartoDB.Positron") %>%
addPolygons(data = foo,
fillColor = cols_code,
fillOpacity = 0.9,
color = "white",
weight = 1)
但当我尝试使用此对象添加图例时,出现以下错误:
addLegend(pal = cols_code,
values = foo$bar,
title = "title",
labFormat = labelFormat(suffix = " things"),
opacity = 0.9)
Error in if (type == "numeric") { : argument is of length zero
我试过使用小册子colo rBin和colorNumeric,而不是他们认为我的休息,而是覆盖在他们自己的间隔在传说和专题。
欢迎任何建议,我想避免将它们转换为因子,因为我可以看到findColours和colorBin函数都附有调色板,但它似乎只是查看传单colorBins/numeric。
嗨蒂姆,谢谢你的回复。我基本上希望我的传奇被上色并从我的classIntervals()中分成五个自然分隔箱。这使用findColours对象在我的传单地图中显示颜色,但我似乎无法将其添加为传说!当我尝试将它添加为传说时,我得到了该错误。 – MrMonkeyBum
当我尝试colorBin'pal_volume <-colorBin(palette =“YlGnBu”,domain = cols_classes $ brks,bins = length(cols_classes $ brks))'它似乎给我7个垃圾箱而不是我想要的五个! – MrMonkeyBum
确定已经想通了,我需要添加pretty = FALSE到colorBin()函数和bin = classInterval $ brks所以'pal_volume <-colorBin(palette =“YlGnBu”, domain = cols_classes $ brks, bins = cols_classes $ brks,pretty = FALSE)'。再次感谢您的回应! – MrMonkeyBum