Skip to content

Commit

Permalink
fixed bug #827
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Feb 9, 2024
1 parent 975d14b commit d528d77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 70 deletions.
8 changes: 4 additions & 4 deletions R/process_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ preprocess_meta = function(o, cdt) {
per_col = any(is.na(cdt$by1__) & !is.na(cdt$by2__) & cdt$class == "autoout"),
per_facet = any(!is.na(cdt$by1__) & !is.na(cdt$by2__) & cdt$class == "autoout"))
}
legend.present.fix = c(any(cdt$class == "out" & identical(cdt$cell.v, "bottom")),
any(cdt$class == "out" & identical(cdt$cell.h, "left")),
any(cdt$class == "out" & identical(cdt$cell.v, "top")),
any(cdt$class == "out" & identical(cdt$cell.h, "right")))
legend.present.fix = c(any(cdt$class == "out" & cdt$cell.v == "bottom"),
any(cdt$class == "out" & cdt$cell.h == "left"),
any(cdt$class == "out" & cdt$cell.v == "top"),
any(cdt$class == "out" & cdt$cell.h == "right"))
}


Expand Down
104 changes: 38 additions & 66 deletions sandbox/issues.R
Original file line number Diff line number Diff line change
Expand Up @@ -530,88 +530,60 @@ tm_shape(World) +

###########################################################
#
# https://github.com/r-tmap/tmap/issues/828
# https://github.com/r-tmap/tmap/issues/832 (solved)
#
###########################################################
library(terra)

pkg <- c("tmap", "tmaptools", "dplyr", "terra", "geobr", "sf",
"RColorBrewer", "grDevices", "stringr")


sapply(pkg, require, character.only = T)

rm(list = ls())


setwd("C:/R/clara_mestrado")


lr <- list.files(path = "laser_drone_rema/predict_nee_er_ensemble",
pattern = ".tif$", recursive = T, full.names = T) %>%
grep(pattern = "summary", value = T) %>%
rast()



# without using breaks
tm_shape(lr[["er_mean"]], raster.downsample = T) +
tm_raster(

col.scale = tm_scale(
midpoint = NA,

n = 11,
values = rev(colorRampPalette(brewer.pal(11, "Spectral"))(11))))

tm_shape(vect(cbind(0:1, 0:1), type = "l")) +
tm_lines() +
tm_shape(rast(matrix(1))) +
tm_raster(col_alpha = 0.2)

###########################################################
#
# https://github.com/r-tmap/tmap/issues/821
#
###########################################################
tm_shape(vect(cbind(c(0, 1852 * 60), c(0, 1852 * 60)), type = "l", crs = "+proj=laea")) +
tm_lines() +
tm_shape(rast(matrix(1), crs = "EPSG:4326")) +
tm_raster(col_alpha = 1)


###########################################################
#
# https://github.com/r-tmap/tmap/issues/828
# https://github.com/r-tmap/tmap/issues/827
#
###########################################################
pkg = c("tmap", "tmaptools", "dplyr", "terra", "geobr", "sf",
"RColorBrewer", "grDevices", "stringr")
sapply(pkg, require, character.only = T)

library(terra)

lr <- rast("sandbox/er_mean.tif")
library(sf)
library(tmap)
library(spData)

packageVersion("tmap")
#> [1] '3.99.9000'

# Left/Top and Center/Top overlap
# Legend/Title are inside rather than outside even though tm_pos_out is used
tm_shape(nz)+
tm_fill(fill = "Island", fill.scale = tm_scale_categorical(values=c("red", "#FFEBBE")))+
tm_title("a)")#+
#tm_layout(legend.position = tm_pos_out("left", "top"),
# title.position = tm_pos_out("center", "top"))

# without using breaks
tm_shape(lr[["er_mean"]], raster.downsample = T) +
tm_raster(

col.scale = tm_scale(
midpoint = NA,

n = 11,
values = rev(colorRampPalette(brewer.pal(11, "Spectral"))(11))))
tm_shape(nz)+
tm_fill(fill = "Island", fill.scale = tm_scale_categorical(values=c("red", "#FFEBBE")),
fill.legend = tm_legend(position = tm_pos_out("left", "top")))+
tm_title("a)", position = tm_pos_out("center", "top"))

tm_shape(nz)+
tm_fill(fill = "Island", fill.scale = tm_scale_categorical(values=c("red", "#FFEBBE")),
fill.legend = tm_legend(position = tm_pos_out("left", "top")))

tm_shape(lr, raster.downsample = T) +
tm_raster(
col.scale = tm_scale(
midpoint = NA,
n = 11,
values = "-brewer.spectral",
values.range = c(0,1)))
tm_shape(World) +
tm_polygons("HPI") +
tm_place_legends_right()

tm_shape(World) +
tm_polygons("HPI") +
tm_place_legends_inside()

tm_shape(lr[["er_mean"]], raster.downsample = T) +
tm_raster(
col.scale = tm_scale(
style = "fixed",
midpoint = NA,
breaks = c(-Inf, seq(-0.05, 0, length.out = 5),
seq(0, 1.9, length.out = 5)[-1], +Inf),
values = "-brewer.spectral",
values.range = c(0,1)))
tm_shape(World) +
tm_polygons("HPI", fill.legend = tm_legend(position = tm_pos_out("left", "top")))

0 comments on commit d528d77

Please sign in to comment.