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

Adding compass and scale_bar only once in tm_facets #837

Open
bappa10085 opened this issue Feb 16, 2024 · 1 comment
Open

Adding compass and scale_bar only once in tm_facets #837

bappa10085 opened this issue Feb 16, 2024 · 1 comment

Comments

@bappa10085
Copy link

I want to add compass and scale_bar only once while using tm_facets. Here is an example code

library(tmap)
library(stars)
library(terra)

#Read some data
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = rast(tif)

#Plot it using tmap r package
tm_shape(x) +
  tm_raster(style="quantile")+
  tm_facets(nrow = 3) +
  tm_layout(panel.labels = names(x), 
            legend.outside=T, legend.outside.position = "right",
            legend.position= c("center", "center"),
            legend.text.size = 1,
            legend.format = list(digits = 2, text.separator = "-"))+
  tm_compass(position = c("RIGHT", "BOTTOM"))+
  tm_scale_bar(text.size = 1, position = c("RIGHT", "BOTTOM"))

Rplot

As you can see in the output, all the facets are having compass and scale_bar. How can I add compass and scale_bar in only one facet?

@aonojeghuo
Copy link

aonojeghuo commented Feb 21, 2024

Hi @bappa10085, you can try this:

#Read some data
tif = system.file("tif/L7_ETMs.tif", package = "stars")
x = terra::rast(tif)

#Plot it using tmap r package
tm_shape(x) +    tm_raster(style="quantile")+    tm_facets(nrow = 3) +
 tm_layout(panel.labels = names(x), attr.outside = T,attr.outside.position = "bottom" ,attr.just="right",
        legend.outside=T, legend.outside.position = "right",
        legend.position= c("left", "top"),
        legend.text.size = 0.8,legend.title.size = 0.9,
        legend.format = list(digits = 2, text.separator = "-"))+
tm_compass(position = c("left", "top"))+
tm_scale_bar(text.size = 1, position = c("RIGHT", "top"))

I cant figure out how to move it to the right ouside despite defining it but you now have just 1 scale bar and north arrow

image

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

No branches or pull requests

2 participants