r-tmap / tmap

R package for thematic maps
https://r-tmap.github.io/tmap
GNU General Public License v3.0
859 stars 121 forks source link

tm_raster() migration warning, but no backward compatibility #936

Open goneau opened 3 weeks ago

goneau commented 3 weeks ago

Textbook code from a TÉLUQ class I am following:

# définir la mise en page pour les deux cartes
format_carte <- tm_layout(frame = FALSE, 
                          legend.position = c(0.67,0.04), 
                          legend.title.size = 0.8, 
                          legend.format=c(text.align="right"),
                          legend.bg.color = "white", 
                          legend.frame = "black")

# style fixed.
Efixed <- tm_shape(E) + 
            tm_raster(title = "Élévation(m)",
                      palette = pal.elevation(10),  
                      style = "fixed", 
                      breaks = c(0,100,200,300,400,500,600,700,800,900,1000,1600)) +
            format_carte

# style quantile
Equant <- tm_shape(E) +
            tm_raster(title = "Élévation(m)", 
                      palette=pal.elevation(10),  
                      style="quantile") +
            format_carte

tmap_arrange(Efixed,Equant)

Warning with development version (no image output):

[v3->v4] `tm_raster()`: instead of `style = "fixed"`, use col.scale = `tm_scale_intervals()`.
ℹ Migrate the argument(s) 'style', 'breaks', 'palette' (rename to 'values') to 'tm_scale_intervals(<HERE>)'
[v3->v4] `tm_raster()`: migrate the argument(s) related to the legend of the visual variable `col` namely 'title' to 'col.legend =
tm_legend(<HERE>)'
[v3->v4] `tm_raster()`: instead of `style = "quantile"`, use col.scale = `tm_scale_intervals()`.
ℹ Migrate the argument(s) 'style', 'palette' (rename to 'values') to 'tm_scale_intervals(<HERE>)'
[v3->v4] `tm_raster()`: migrate the argument(s) related to the legend of the visual variable `col` namely 'title' to 'col.legend =
tm_legend(<HERE>)'

Error in l$position$type : $ operator is invalid for atomic vectors

With version 3.3-4:

Capture d’écran, le 2024-09-13 à 11 21 31
mtennekes commented 3 weeks ago

Thx @goneau the error is fixed, but probably the position of the legend will be different. Instead of

legend.position = c(0.67,0.04)

, if you like the legend to be at the bottom right of the map, and still would like to have control over the margins, I would recommend

legend.position = tm_pos_in(0.95, 0.05, just.h = "right", just.v = "bottom")
goneau commented 3 weeks ago

Thank you, I tested and I have an image rendered now, but with different locations for the legend as you mentioned. As I said, it is not my code, but the one from the textbook. Your modification to the location does render as intended by the original author.

Also, I noticed that legend.format=c(text.align="right") don’t have any effect.

mtennekes commented 3 weeks ago

What textbook is it @goneau ? Might be worthwhile for us to contact the author for future releases of the book.

It should be legend.format = list(text.align = "right") also in v3, even though the syntax you mentioned might be working as well in v3.

goneau commented 2 weeks ago

It is not a published textbook per se. It is from an online class at TELUQ university. The lecture is hosted on github.