Manually adding legend values in leaflet

眉间皱痕 提交于 2019-12-30 10:19:12

问题


I'm plotting results from various British elections in Leaflet and ran into a bit of a problem with legends.

For the various results in the general election I'm using the same colour function with different domain for the different data (the yellow-> purple scale in the picture)

This is created with (for the first two as examples):

labvotescols <- colorNumeric(
  c("Yellow", "Purple"),
  domain = Westminster$LabourVotes,
  ukipvotescols <- colorNumeric(
    c("Yellow", "Purple"),
    domain = Westminster$UKIPVotes,

and so on...

Currently I have the legend

map = map %>% addLegend("bottomright", pal = ukipvotescols, values = Westminster$UKIPVotes,
                    title = "(e.g.) % voting UKIP at GE2015",
                    opacity = 1)

as one example of this, but really I'd like to get rid of all the values on the legend and just have "less" at the yellow end and "more" at the purple end. Is this possible?

I tried playing around and then googling but to no avail.


回答1:


You could change it from a yellow->purple scale and make your own scale:

map = map %>% addLegend("bottomright", 
  colors =c("#FFC125",  "#FFC125", "#8A4117", "#7D0552", "#571B7E"),
  labels= c("less", "","","","", "more"),
  title= "(e.g.) % voting UKIP at GE2015"
  opacity = 1)

If you get the correct colors then it should look similar. Not the answer you were looking for, but it's a good workaround. You're output would look like this:

Spend more time looking for better color transition and you could get a legend that looks similar to the yellow-purple color pallet you have up top.



来源:https://stackoverflow.com/questions/38161073/manually-adding-legend-values-in-leaflet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!