TransWikia.com

Reverse legend histogram palette in tmap

Geographic Information Systems Asked on April 11, 2021

I’m trying to plot the histogram values with the same order as the color palette of a raster legend, passing the parameter legend.col.reverse = TRUE reverses the legend but not the histogram, since I’m trying to plot elevation values, it’s desirable to put highest on top of the legend.

EDIT

I can achieve it by plotting the layer twice and passing alternately the legend and histogram, but that’s hacky.

library(tmap)
data("land")
tm_shape(land, ylim = c(14,30), xlim = c(-105, -90)) +
  tm_raster("trees", palette = "Greens", title = "Percent Tree Cover", legend.reverse = T,
            legend.hist = T) +
  tm_layout(legend.bg.color = "white")

enter image description here

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP