Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
goneau opened this issue Sep 13, 2024 · 4 comments
Open

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

goneau opened this issue Sep 13, 2024 · 4 comments

Comments

@goneau
Copy link

goneau commented Sep 13, 2024

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 added a commit that referenced this issue Sep 13, 2024
@mtennekes
Copy link
Member

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
Copy link
Author

goneau commented Sep 14, 2024

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
Copy link
Member

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
Copy link
Author

goneau commented Sep 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants