tmap icon indicating copy to clipboard operation
tmap copied to clipboard

Adding compass and scale_bar only once in `tm_facets`

Open bappa10085 opened this issue 1 year ago • 1 comments

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?

bappa10085 avatar Feb 16 '24 05:02 bappa10085

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

aonojeghuo avatar Feb 21 '24 21:02 aonojeghuo