Skip to content

Commit

Permalink
done #820
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Feb 3, 2024
1 parent 5a14d1b commit 6a9f2e3
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 12 deletions.
12 changes: 9 additions & 3 deletions R/step2_helper_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order)
relevant_vars = c("tmapID__", "sel__" , vars, by123__[b])
dtl = copy(dt[, relevant_vars, with = FALSE])

# edit free argument. If NA, it is set to FALSE, and for the vars dimension to TRUE.
# impute free argument.
fr = rep(aes$free, length.out = 3)
if (anyNA(fr)) {
fr = rep(FALSE, 3)
if (length(v)) fr[v] = TRUE
if (is.null(o$free.scales)) {
# set to FALSE by default, and for the vars dimension to TRUE.
fr = rep(FALSE, 3)
if (length(v)) fr[v] = TRUE
} else {
# v3 backward compatibility: free.scales is set via tm_facets
fr = rep(o$free.scales, length.out = 3)
}
}

# group by variables with free scales
Expand Down
14 changes: 11 additions & 3 deletions R/tm_facets.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#' By default, `scale.factor=2`.
#' @param type `"grid"`, `"wrap"` or `"stack"`
#' @param along deprecated Please use `tm_facets_page()`
#' @param free.scales deprecated. Please use the `.free` arguments in the layer functions, e.g. `fill.free` in `tm_polygons`.
#' @export
#' @rdname tm_facets
#' @name tm_facets
Expand All @@ -71,8 +72,8 @@ tm_facets = function(by = NULL,
textNA = "Mssing",
scale.factor=2,
type = NA, # grid, wrap or stack
along = NULL
) {
along = NULL,
free.scales = NULL) {

calls <- names(match.call(expand.dots = TRUE)[-1])

Expand All @@ -94,7 +95,7 @@ tm_facets = function(by = NULL,



tm_element_list(tm_element(
x = tm_element_list(tm_element(
type = type,
by = by,
rows = rows,
Expand All @@ -114,6 +115,13 @@ tm_facets = function(by = NULL,
scale.factor = scale.factor,
calls = calls,
subclass = "tm_facets"))

if (!is.null(free.scales)) {
message("tm_facets: the argument free.scales is deprecated. Specify this via the layer functions (e.g. fill.free in tm_polygons)")
x + tm_options(free.scales = free.scales)
} else {
x
}
}

#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/tm_layers_lines.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ tm_lines = function(col = tm_const(),
"popup.format", "auto.palette.mapping", "max.categories")

if (any(v3 %in% names(args))) {
message("Deprecated tmap v3 code detected. Code translated to v4")
message("tm_lines: Deprecated tmap v3 code detected. Code translated to v4")
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
style = "pretty"
Expand Down
2 changes: 1 addition & 1 deletion R/tm_layers_polygons.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tm_polygons = function(fill = tm_const(),


if (any(v3 %in% names(args))) {
message("Deprecated tmap v3 code detected. Code translated to v4")
message("tm_polygons: Deprecated tmap v3 code detected. Code translated to v4")
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
style = "pretty"
Expand Down
2 changes: 1 addition & 1 deletion R/tm_layers_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ tm_raster = function(col = tm_shape_vars(),
"max.categories", "max.value")

if (any(v3 %in% names(args))) {
message("Deprecated tmap v3 code detected. Code translated to v4")
message("tm_raster: Deprecated tmap v3 code detected. Code translated to v4")
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
style = "pretty"
Expand Down
2 changes: 1 addition & 1 deletion R/tm_layers_symbols.R
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ v3_symbols = function(args, args_called) {
"auto.palette.mapping", "max.categories")

if (any(v3 %in% names(args))) {
message("Deprecated tmap v3 code detected. Code translated to v4")
message("tm_symbols: Deprecated tmap v3 code detected. Code translated to v4")
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
style = "pretty"
Expand Down
2 changes: 1 addition & 1 deletion R/tm_layers_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ tm_text = function(text = tm_const(),


if (any(v3 %in% names(args))) {
message("Deprecated tmap v3 code detected. Code translated to v4")
message("tm_text: Deprecated tmap v3 code detected. Code translated to v4")
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
style = "pretty"
Expand Down
4 changes: 3 additions & 1 deletion R/tmap_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# facets
facet.max = 64, # was max.facets
facet.flip = FALSE,
free.scales = NULL, # for backward compatibility: if this value is set, it will be used to impute the free arguments in the layer functions

# spatial object class specific options
raster.max.cells = 1e6, # was max.raster
Expand Down Expand Up @@ -745,7 +746,8 @@ complete_options = function(x, o) {
#' | `crs` | Map crs (see [tm_shape()]). `NA` means the crs is specified in [tm_shape()]. The crs that is used by the transformation functions is defined in [tm_shape()].|
#' | `facet.max` | Maximum number of facets |
#' | `facet.flip` | Should facets be flipped (in case of facet wrap)? This can also be set via [tm_facets_flip()] |
#' | `raster.max.cells` | Maximum number of raster grid cells |
#' | `free.scales` | For backward compatibility: if this value is set, it will be used to impute the free arguments in the layer functions |
#' | `raster.max.cells` | Maximum number of raster grid cells |
#' | `show.messages` | Show messages? |
#' | `show.warnings` | Show warnings? |
#' | `output.format` | Output format |
Expand Down

0 comments on commit 6a9f2e3

Please sign in to comment.