diff --git a/NAMESPACE b/NAMESPACE index 86499d0f..d30084c1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -171,6 +171,7 @@ export(tm_graticules) export(tm_grid) export(tm_iso) export(tm_labels) +export(tm_labels_highlighted) export(tm_layout) export(tm_legend) export(tm_legend_combine) diff --git a/R/tm_layers_iso.R b/R/tm_layers_iso.R new file mode 100644 index 00000000..8d53c5bc --- /dev/null +++ b/R/tm_layers_iso.R @@ -0,0 +1,24 @@ +#' Map layer: iso (contour) +#' +#' Map layer that draws iso (contour) lines. Stack of [tm_lines()] and [tm_labels_highlighed]. +#' +#' @param col Visual variable that determines the color of the lines +#' @param text Visual variable that determines the text +#' @param ... passed on to [tm_lines()] and [tm_labels_highlighted()]. For the text color and alpha transparency of the text labels, please use `text_col` and `text_alpha` instead of `col` and `col_alpha`. +#' @export +tm_iso = function(col, text, ...) { + args = list(...) + argsL = args[intersect(names(formals("tm_lines")), names(args))] + + nms_col = c("col", "col.scale", "col.legend", "col.chart", "col.free", "col_alpha", "col_alpha.scale", "col_alpha.legend", "col_alpha.chart", "col_alpha.free") + + # update args for labels + args[nms_col] = NULL + rename_id = names(args) %in% paste0("text_", nms_col) + + names(args)[rename_id] = substr(names(args)[rename_id], 6, nchar(names(args)[rename_id])) + argsT = args[intersect(names(formals("tm_labels_highlighted")), names(args))] + + do.call("tm_lines", c(list(col=col), argsL)) + + do.call("tm_labels_highlighted", c(list(text=text), argsT)) +} diff --git a/R/tm_layers_lines.R b/R/tm_layers_lines.R index 27f057f8..dbf2fa93 100644 --- a/R/tm_layers_lines.R +++ b/R/tm_layers_lines.R @@ -8,7 +8,7 @@ opt_tm_lines = function(lines.only = "ifany") { #' Map layer: lines #' -#' Map layer that draws symbols Supported visual variables are: `col` (the color), `lwd` (line width), `lty` (line type), and `col_alpha` (color alpha transparency). +#' Map layer that draws lines. Supported visual variables are: `col` (the color), `lwd` (line width), `lty` (line type), and `col_alpha` (color alpha transparency). #' #' The visual variable arguments (e.g. `col`) can be specified with either a data #' variable name (e.g., a spatial vector attribute or a raster layer of the object diff --git a/R/tm_layers_text.R b/R/tm_layers_text.R index 8e8e15fb..b6085fe1 100644 --- a/R/tm_layers_text.R +++ b/R/tm_layers_text.R @@ -69,6 +69,8 @@ opt_tm_labels = function(points.only = "ifany", opt_tm_markers = function(markers.on.top.of.text = FALSE, points.only = "ifany", shadow = FALSE, + shadow.offset.x = 0.1, + shadow.offset.y = 0.1, just = "center", along.lines = TRUE, bg.padding = 0.4, @@ -83,6 +85,8 @@ opt_tm_markers = function(markers.on.top.of.text = FALSE, list(markers = list(markers.on.top.of.text = markers.on.top.of.text), text = opt_tm_labels(points.only = points.only, shadow = shadow, + shadow.offset.x = shadow.offset.x, + shadow.offset.y = shadow.offset.y, just = just, along.lines = along.lines, bg.padding = bg.padding, @@ -141,8 +145,14 @@ opt_tm_markers = function(markers.on.top.of.text = FALSE, #' @param fontface,fontface.scale,fontface.legend,fontface.chart,fontface.free Visual variable that determines #' the font face. See Details. #' @param fontfamily The font family. See [gpar()][grid::gpar()] for details. -#' @param shadow Shadow behind the text. Logical or color. -#' @param shadow.offset.x,shadow.offset.y Shadow offset in line heights +#' @param bgcol,bgcol.scale,bgcol.legend,bgcol.chart,bgcol.free Visual variable that determines +#' the background color. See Details. +#' @param bgcol_alpha,bgcol_alpha.scale,bgcol_alpha.legend,bgcol_alpha.chart,bgcol_alpha.free Visual variable that determines +#' the background color transparency. See Details. +#' @param xmod,xmod.scale,xmod.legend,xmod.chart,xmod.free Transformation variable that determines the x offset. See details. +#' @param ymod,ymod.scale,ymod.legend,ymod.chart,ymod.free Transformation variable that determines the y offset. See details. +#' the text. See details. +#' @param angle,angle.scale,angle.legend,angle.chart,angle.free Rotation angle #' @param plot.order Specification in which order the spatial features are drawn. #' See [tm_plot_order()] for details. #' @param zindex Map layers are drawn on top of each other. The `zindex` numbers @@ -155,15 +165,9 @@ opt_tm_markers = function(markers.on.top.of.text = FALSE, #' (meaning only one group can be shown), `"check"` for check boxes (so multiple groups can be shown), #' and `"none"` for no control (the group cannot be (de)selected). #' @param options options passed on to the corresponding `opt_` function -#' @param bgcol,bgcol.scale,bgcol.legend,bgcol.chart,bgcol.free Visual variable that determines -#' the background color. See Details. -#' @param bgcol_alpha,bgcol_alpha.scale,bgcol_alpha.legend,bgcol_alpha.chart,bgcol_alpha.free Visual variable that determines -#' the background color transparency. See Details. -#' @param xmod,xmod.scale,xmod.legend,xmod.chart,xmod.free Transformation variable that determines the x offset. See details. -#' @param ymod,ymod.scale,ymod.legend,ymod.chart,ymod.free Transformation variable that determines the y offset. See details. -#' the text. See details. -#' @param angle,angle.scale,angle.legend,angle.chart,angle.free Rotation angle #' @param points.only should only point geometries of the shape object (defined in [tm_shape()]) be plotted? By default `"ifany"`, which means `TRUE` in case a geometry collection is specified. +#' @param shadow Shadow behind the text. Logical or color. +#' @param shadow.offset.x,shadow.offset.y Shadow offset in line heights #' @param just justification of the text relative to the point coordinates. Either one of the following values: \code{"left"} , \code{"right"}, \code{"center"}, \code{"bottom"}, and \code{"top"}, or a vector of two values where first value specifies horizontal and the second value vertical justification. Besides the mentioned values, also numeric values between 0 and 1 can be used. 0 means left justification for the first value and bottom justification for the second value. Note that in view mode, only one value is used. #' @param along.lines logical that determines whether labels are rotated along the spatial lines. Only applicable if a spatial lines shape is used. #' @param bg.padding The padding of the background in terms of line heights. @@ -522,6 +526,75 @@ tm_labels = function(text = tm_const(), tm } + + +#' @rdname tm_text +#' @name tm_labels_highlighted +#' @export +tm_labels_highlighted = function(text = tm_const(), + text.scale = tm_scale(), + text.legend = tm_legend(), + text.chart = tm_chart_none(), + text.free = NA, + size = tm_const(), + size.scale = tm_scale(), + size.legend = tm_legend(), + size.chart = tm_chart_none(), + size.free = NA, + col = tm_const(), + col.scale = tm_scale(), + col.legend = tm_legend(), + col.chart = tm_chart_none(), + col.free = NA, + col_alpha = tm_const(), + col_alpha.scale = tm_scale(), + col_alpha.legend = tm_legend(), + col_alpha.chart = tm_chart_none(), + col_alpha.free = NA, + fontface = tm_const(), + fontface.scale = tm_scale(), + fontface.legend = tm_legend(), + fontface.chart = tm_chart_none(), + fontface.free = NA, + fontfamily = "", + bgcol = tm_const(), + bgcol.scale = tm_scale(), + bgcol.legend = tm_legend(), + bgcol.chart = tm_chart_none(), + bgcol.free = NA, + bgcol_alpha = tm_const(), + bgcol_alpha.scale = tm_scale(), + bgcol_alpha.legend = tm_legend(), + bgcol_alpha.chart = tm_chart_none(), + bgcol_alpha.free = NA, + xmod = 0, + xmod.scale = tm_scale(), + xmod.legend = tm_legend_hide(), + xmod.chart = tm_chart_none(), + xmod.free = NA, + ymod = 0, + ymod.scale = tm_scale(), + ymod.legend = tm_legend_hide(), + ymod.chart = tm_chart_none(), + ymod.free = NA, + angle = 0, + angle.scale = tm_scale(), + angle.legend = tm_legend_hide(), + angle.chart = tm_chart_none(), + angle.free = NA, + plot.order = tm_plot_order("AREA", reverse = FALSE, na.order = "bottom"), + zindex = NA, + group = NA, + group.control = "check", + options = opt_tm_labels(), + ...) { + args = c(as.list(environment()), list(...)) + tm = do.call(tm_text, args) + tm[[1]]$layer = c("labels_highlighted", "text") + tm +} + + #' @rdname tm_text #' @name tm_markers #' @export diff --git a/R/tmap_options.R b/R/tmap_options.R index 698faa6c..891ac0d7 100644 --- a/R/tmap_options.R +++ b/R/tmap_options.R @@ -64,6 +64,7 @@ tmapMode = function(id, name, ...) { col.symbols = "grey40", col.raster = "grey40", col = "black", + bgcol.labels_highlighted = "white", bgcol = "#00000000", lwd = 1, lty = "solid", diff --git a/R/v4-not-implemented.R b/R/v4-not-implemented.R index be7a07a0..700684d8 100644 --- a/R/v4-not-implemented.R +++ b/R/v4-not-implemented.R @@ -4,11 +4,6 @@ #' @name v4-not-yet NULL -#' @export -#' @rdname v4-not-yet -tm_iso <- function(...) { - stop("Not yet implemented in v4") -} #' @export #' @rdname v4-not-yet tm_logo <- function(...) { @@ -39,4 +34,4 @@ tmap_style_catalog <- function(...) { #' @rdname v4-not-yet tmap_style_catalogue <- function(...) { stop("Not yet implemented in v4") -} \ No newline at end of file +} diff --git a/man/tm_iso.Rd b/man/tm_iso.Rd new file mode 100644 index 00000000..b2e578ff --- /dev/null +++ b/man/tm_iso.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tm_layers_iso.R +\name{tm_iso} +\alias{tm_iso} +\title{Map layer: iso (contour)} +\usage{ +tm_iso(col, text, ...) +} +\arguments{ +\item{col}{Visual variable that determines the color of the lines} + +\item{text}{Visual variable that determines the text} + +\item{...}{passed on to \code{\link[=tm_lines]{tm_lines()}} and \code{\link[=tm_labels_highlighted]{tm_labels_highlighted()}}. For the text color and alpha transparency of the text labels, please use \code{text_col} and \code{text_alpha} instead of \code{col} and \code{col_alpha}.} +} +\description{ +Map layer that draws iso (contour) lines. Stack of \code{\link[=tm_lines]{tm_lines()}} and \link{tm_labels_highlighed}. +} diff --git a/man/tm_lines.Rd b/man/tm_lines.Rd index 620c07c5..168715b6 100644 --- a/man/tm_lines.Rd +++ b/man/tm_lines.Rd @@ -76,7 +76,7 @@ tm_lines( \item{...}{to catch deprecated arguments from version < 4.0} } \description{ -Map layer that draws symbols Supported visual variables are: \code{col} (the color), \code{lwd} (line width), \code{lty} (line type), and \code{col_alpha} (color alpha transparency). +Map layer that draws lines. Supported visual variables are: \code{col} (the color), \code{lwd} (line width), \code{lty} (line type), and \code{col_alpha} (color alpha transparency). } \details{ The visual variable arguments (e.g. \code{col}) can be specified with either a data diff --git a/man/tm_text.Rd b/man/tm_text.Rd index 7a18775d..5878c51e 100644 --- a/man/tm_text.Rd +++ b/man/tm_text.Rd @@ -6,6 +6,7 @@ \alias{opt_tm_markers} \alias{tm_text} \alias{tm_labels} +\alias{tm_labels_highlighted} \alias{tm_markers} \title{Map layer: text} \usage{ @@ -43,6 +44,8 @@ opt_tm_markers( markers.on.top.of.text = FALSE, points.only = "ifany", shadow = FALSE, + shadow.offset.x = 0.1, + shadow.offset.y = 0.1, just = "center", along.lines = TRUE, bg.padding = 0.4, @@ -176,6 +179,66 @@ tm_labels( ... ) +tm_labels_highlighted( + text = tm_const(), + text.scale = tm_scale(), + text.legend = tm_legend(), + text.chart = tm_chart_none(), + text.free = NA, + size = tm_const(), + size.scale = tm_scale(), + size.legend = tm_legend(), + size.chart = tm_chart_none(), + size.free = NA, + col = tm_const(), + col.scale = tm_scale(), + col.legend = tm_legend(), + col.chart = tm_chart_none(), + col.free = NA, + col_alpha = tm_const(), + col_alpha.scale = tm_scale(), + col_alpha.legend = tm_legend(), + col_alpha.chart = tm_chart_none(), + col_alpha.free = NA, + fontface = tm_const(), + fontface.scale = tm_scale(), + fontface.legend = tm_legend(), + fontface.chart = tm_chart_none(), + fontface.free = NA, + fontfamily = "", + bgcol = tm_const(), + bgcol.scale = tm_scale(), + bgcol.legend = tm_legend(), + bgcol.chart = tm_chart_none(), + bgcol.free = NA, + bgcol_alpha = tm_const(), + bgcol_alpha.scale = tm_scale(), + bgcol_alpha.legend = tm_legend(), + bgcol_alpha.chart = tm_chart_none(), + bgcol_alpha.free = NA, + xmod = 0, + xmod.scale = tm_scale(), + xmod.legend = tm_legend_hide(), + xmod.chart = tm_chart_none(), + xmod.free = NA, + ymod = 0, + ymod.scale = tm_scale(), + ymod.legend = tm_legend_hide(), + ymod.chart = tm_chart_none(), + ymod.free = NA, + angle = 0, + angle.scale = tm_scale(), + angle.legend = tm_legend_hide(), + angle.chart = tm_chart_none(), + angle.free = NA, + plot.order = tm_plot_order("AREA", reverse = FALSE, na.order = "bottom"), + zindex = NA, + group = NA, + group.control = "check", + options = opt_tm_labels(), + ... +) + tm_markers( text = tm_const(), text.scale = tm_scale(), diff --git a/man/v4-not-yet.Rd b/man/v4-not-yet.Rd index a51e880b..5fe639a0 100644 --- a/man/v4-not-yet.Rd +++ b/man/v4-not-yet.Rd @@ -2,7 +2,6 @@ % Please edit documentation in R/v4-not-implemented.R \name{v4-not-yet} \alias{v4-not-yet} -\alias{tm_iso} \alias{tm_logo} \alias{tmap_grob} \alias{tm_rgba} @@ -11,8 +10,6 @@ \alias{tmap_style_catalogue} \title{Features not yet implemented in tmap4} \usage{ -tm_iso(...) - tm_logo(...) tmap_grob(...)