I got this plot
using this script
library(raster)
library(tmap)
library(classInt)
download.file("https://github.com/mtennekes/tmap/files/5500015/Difference.tif.zip",
"Difference.tif.zip")
unzip("Difference.tif.zip", "Difference.tif")
diff <- raster("Difference.tif")
diff_values <- getValues(diff)
diff_values_below0 <- diff_values[diff_values < 0]
diff_values_above0 <- diff_values[diff_values > 0]
classes1 <- classIntervals(diff_values_below0, n = 4, style = "fisher")
classes2 <- classIntervals(diff_values_above0, n = 4, style = "fisher")
all_classes <- c(classes1$brks, classes2$brks)
diff_map<-
tm_shape(diff) +
tm_raster(midpoint = 0,
breaks = all_classes,
palette = "RdBu")+
tm_layout(legend.outside = TRUE)
tmap_save(diff_map, "diff_map.png", width=1000, height=700,dpi = 150)
As you can see, there is white space to the right of the legend. I tried removing it using outer.margins
but none of my trials worked.
Any suggestions on how this can be done?