tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Suggestion: legend ticks

Open Nowosad opened this issue 5 years ago • 1 comments

library(tmap)
library(spData)

# pretty
tm_shape(world) +
  tm_polygons(col = "lifeExp", 
              style = "pretty",
              palette = "viridis")
#> Linking to GEOS 3.8.1, GDAL 3.0.4, PROJ 6.3.2

@mtennekes have you ever considered adding legend ticks for continuous maps? Right not, it is hard to exactly know which color is connected to which value. (Some examples: https://i.stack.imgur.com/yyDx3.png and https://i.stack.imgur.com/pSXx0.png)


# cont 1
tm_shape(world) +
  tm_polygons(col = "lifeExp",
              style = "cont",
              palette = "viridis")


# cont 2
tm_shape(world) +
  tm_polygons(col = "lifeExp",
              style = "cont",
              palette = "viridis",
              legend.is.portrait = FALSE)
#> Legend labels were too wide. Therefore, legend.text.size has been set to 0.6. Increase legend.width (argument of tm_layout) to make the legend wider and therefore the labels larger.

Created on 2020-10-07 by the reprex package (v0.3.0)

Nowosad avatar Oct 07 '20 06:10 Nowosad

How can i set legend ticks for continuous maps? I'm using tmap and I have this difficulty

hmandela avatar Feb 19 '21 08:02 hmandela

Available in the upcoming tmap v4:

library(tmap)
library(spData)

# cont 1
tm_shape(world) +
  tm_polygons(col = "lifeExp",
              style = "cont",
              palette = "viridis")
#> Deprecated tmap v3 code detected. Code translated to v4
#> Warning: Some legend items do not fit with the specified font size, and
#> therefore were rescaled.

Nowosad avatar Feb 18 '23 19:02 Nowosad

Dear Nowosad, The legend ticks of tmap V4 work in tm_polygons function, but does not work in tm_raster( ) function.

# remotes::install_github("r-tmap/tmap@v4")
library(tmap)
data(land, World)

tm_shape(land) +
  tm_raster("elevation", col.scale = tm_scale_continuous(values = terrain.colors(9))) +
  tm_shape(World) +
  tm_borders()


# compare legends side by side
tm_shape(land) +
  tm_raster("elevation", col.scale = tm_scale_continuous(values = terrain.colors(9))) +
  tm_shape(World) +
  tm_polygons("life_exp", fill.scale = tm_scale_continuous(values = terrain.colors(9)))

Created on 2023-02-21 with reprex v2.0.2

Yelong-Z avatar Feb 21 '23 04:02 Yelong-Z

Thanks for letting us know. I opened a new issue for this problem -- https://github.com/r-tmap/tmap/issues/702

Nowosad avatar Feb 21 '23 08:02 Nowosad

@Yelong-Z I should work now.

Nowosad avatar Feb 21 '23 13:02 Nowosad