-1

I created a map with the following code

 tm_shape(data) +
  tm_borders("grey")  +
  tm_fill("Greenspace",style = "quantile", legend.reverse = TRUE, title = "% green", palette = "BuGn") +
 tm_layout(legend.position = c(0.82,0.65), legend.bg.color = "aliceblue",legend.text.size = 0.55,
            title= "Green Space in Principality of Liechtenstein", title.size = 1.7,
            title.position = c('centre', 'top'))   + tm_scale_bar(position=c(0.72, 0.125),width = 0.15)

Now the legend of the map has bad numbers. Numbers are duplicated like these: enter image description here

Is there a function where I can change the numbers to

39.19 to 63.27

33.00 to 39.1899

29.17 to 32.99

22.65 to 29.169

12.54 to 22.649

1
  • I'm not sure if there's a way to adjust the automatically created tmap legend, but you can add your own legend with tm_add_legend and configure it pretty much from scratch. They show it a little bit in this post stackoverflow.com/questions/66169555/…
    – Randcelot
    Aug 21 at 18:10

1 Answer 1

0

As Randcelot suggests, I think it would be best to append a custom legend using something similar to the following:

tm_add_legend("fill",
              title="",
              is.portrait = TRUE,
              labels=c("39.19 to 63.27","33.00 to 39.1899","29.17 to 32.99","22.65 to 29.169","12.54 to 22.649"))

Since it looks like your preferred legend has the same values, just with a few more significant digits, revising your tm_fill() argument as follows might be another way to get close to what you're after:

tm_fill("Greenspace",
        style = "quantile", 
        legend.reverse = TRUE, 
        title = "% green", 
        palette = "BuGn",
        legend.format=list(digits=4)) +

If you edit your question so that it is a true reprex with some example data to work with, we can help you get a bit closer to something that works for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy