From 3e9a0306330af9e1223e0d2f9048845f4a22a989 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 15:49:27 -0400 Subject: [PATCH 1/7] Change deprecation warning into a message (for now) (appease CRAN) #805 --- R/step1_rearrange.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/step1_rearrange.R b/R/step1_rearrange.R index c82a151b..acbaae7d 100644 --- a/R/step1_rearrange.R +++ b/R/step1_rearrange.R @@ -50,7 +50,7 @@ step1_rearrange = function(tmel) { if (any(is_opt)) for (id in which(is_opt)) { o2 = oth[[id]] - if ("v3" %in% o2$calls) warning("v3 code detected: as of tmap v4, tm_legend should be specified per visual variable (e.g. with the argument fill.legend of tm_polygons", call. = FALSE) + if ("v3" %in% o2$calls) message("v3 code detected: as of tmap v4, the legend should be specified for each visual variable\n(e.g. with `fill.legend = tm_legend()` inside tm_polygons to control the legend of fill for polygons.", call. = FALSE) # special case: position, in case c("left", "top") is used pids = grep(".position", names(o2), fixed = TRUE) From b1c087483c76ec2cce5c77097dbbe275dad593d6 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 16:20:12 -0400 Subject: [PATCH 2/7] Try to address some check notes + fix typo --- NAMESPACE | 5 ++++- R/misc_pointLabel.R | 34 +++++++++++++++++----------------- R/tm_layers_cartogram.R | 2 ++ R/tm_layers_symbols.R | 4 ++-- R/tmapScaleAsIs.R | 2 +- examples/tm_symbols.R | 15 +++++++++++---- examples/tm_text.R | 15 ++++++++++----- man/tm_cartogram.Rd | 30 ++++++++++++++++++++---------- man/tm_shape.Rd | 4 ++++ man/tm_symbols.Rd | 20 +++++++++++++------- man/tm_text.Rd | 16 ++++++++++------ 11 files changed, 94 insertions(+), 53 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 7e184895..53261f2a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -121,13 +121,16 @@ export(get_fact_levels_na) export(make_by_vars) export(marker_icon) export(opt_tm_bubbles) +export(opt_tm_cartogram) +export(opt_tm_cartogram_dorling) +export(opt_tm_cartogram_ncont) export(opt_tm_dots) export(opt_tm_labels) export(opt_tm_lines) export(opt_tm_polygons) export(opt_tm_raster) export(opt_tm_sf) -export(opt_tm_sqaures) +export(opt_tm_squares) export(opt_tm_symbols) export(opt_tm_text) export(providers) diff --git a/R/misc_pointLabel.R b/R/misc_pointLabel.R index 79f26ac2..da141681 100644 --- a/R/misc_pointLabel.R +++ b/R/misc_pointLabel.R @@ -1,44 +1,44 @@ test_rect = function(x, y, width, height, bbx) { - library(grid) - grid.newpage() + # library(grid) + grid::grid.newpage() asp = tmaptools::get_asp_ratio(bbx) if (asp > 1) { - pushViewport(viewport(width = unit(1, "snpc"), height = unit(1/asp, "snpc"))) + grid::pushViewport(grid::viewport(width = grid::unit(1, "snpc"), height = grid::unit(1/asp, "snpc"))) } else { - pushViewport(viewport(width = unit(asp, "snpc"), height = unit(1, "snpc"))) + grid::pushViewport(grid::viewport(width = grid::unit(asp, "snpc"), height = grid::unit(1, "snpc"))) } - pushViewport(viewport(xscale = bbx[c(1,3)], yscale = bbx[c(2,4)])) - grid.rect() + grid::pushViewport(grid::viewport(xscale = bbx[c(1,3)], yscale = bbx[c(2,4)])) + grid::grid.rect() mapply(function(xi,yi,wi,hi) { - grid.rect(x = unit(xi, "native"), y = unit(yi, "native"), width = unit(wi, "native"), height = unit(hi, "native"), gp = gpar(fill = "orange", col = "black")) + grid::grid.rect(x = grid::unit(xi, "native"), y = grid::unit(yi, "native"), width = grid::unit(wi, "native"), height = grid::unit(hi, "native"), gp = grid::gpar(fill = "orange", col = "black")) }, x, y, width, height) - upViewport(2) + grid::upViewport(2) } test_poly = function(xs, ys, bbx) { - library(grid) - grid.newpage() + # library(grid) + grid::grid.newpage() asp = tmaptools::get_asp_ratio(bbx) if (asp > 1) { - pushViewport(viewport(width = unit(1, "snpc"), height = unit(1/asp, "snpc"))) + grid::pushViewport(grid::viewport(width = grid::unit(1, "snpc"), height = grid::unit(1/asp, "snpc"))) } else { - pushViewport(viewport(width = unit(asp, "snpc"), height = unit(1, "snpc"))) + grid::pushViewport(grid::viewport(width = grid::unit(asp, "snpc"), height = grid::unit(1, "snpc"))) } - pushViewport(viewport(xscale = bbx[c(1,3)], yscale = bbx[c(2,4)])) + grid::pushViewport(grid::viewport(xscale = bbx[c(1,3)], yscale = bbx[c(2,4)])) - grid.rect() + grid::grid.rect() - grid.path(x = unit(xs, "native"), y = unit(ys, "native"), gp = gpar(fill = "orange", col = "black")) + grid::grid.path(x = grid::unit(xs, "native"), y = grid::unit(ys, "native"), gp = grid::gpar(fill = "orange", col = "black")) - upViewport(2) + grid::upViewport(2) } # function adapted from car::pointLabel @@ -74,7 +74,7 @@ pointLabel2 <- function (x, y, width, height, bbx, } - z <- xy.coords(x, y, recycle = TRUE) + z <- grDevices::xy.coords(x, y, recycle = TRUE) z <- toUnityCoords(z) x <- z$x y <- z$y diff --git a/R/tm_layers_cartogram.R b/R/tm_layers_cartogram.R index 91412795..476d7010 100644 --- a/R/tm_layers_cartogram.R +++ b/R/tm_layers_cartogram.R @@ -1,3 +1,5 @@ +#' @param type,itermax,expansion,inplace,share Additional options +#' #' @rdname tm_cartogram #' @name opt_tm_cartogram #' @export diff --git a/R/tm_layers_symbols.R b/R/tm_layers_symbols.R index e944ef10..467bd06f 100644 --- a/R/tm_layers_symbols.R +++ b/R/tm_layers_symbols.R @@ -24,7 +24,7 @@ opt_tm_bubbles = opt_tm_symbols #' @rdname tm_symbols #' @name opt_tm_squares #' @export -opt_tm_sqaures = opt_tm_symbols +opt_tm_squares = opt_tm_symbols @@ -563,7 +563,7 @@ tm_squares = function(size = tm_const(), zindex = NA, group = NA, group.control = "check", - options = opt_tm_sqaures(), + options = opt_tm_squares(), ...) { args = c(as.list(environment()), list(...)) diff --git a/R/tmapScaleAsIs.R b/R/tmapScaleAsIs.R index 6e1ca50f..9d4189ac 100644 --- a/R/tmapScaleAsIs.R +++ b/R/tmapScaleAsIs.R @@ -55,7 +55,7 @@ most_common_cat = function(x) { tab = table(x) nm = names(tab)[which.max(tab)] tryCatch({ - as(nm, cls) + methods::as(nm, cls) }, error = function(e) { nm }) diff --git a/examples/tm_symbols.R b/examples/tm_symbols.R index 3387c99f..98a63359 100644 --- a/examples/tm_symbols.R +++ b/examples/tm_symbols.R @@ -3,17 +3,24 @@ Africa = World[World$continent == "Africa", ] tm_shape(land) + tm_raster("cover_cls", - col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), + col.scale = tm_scale( + values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)] + ), col.legend = tm_legend_hide()) + tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), col = cols4all::c4a("brewer.pastel1")[2]) + + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), + col = cols4all::c4a("brewer.pastel1")[2]) + tm_shape(Africa, is.main = TRUE) + tm_borders() + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", - size.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2)), + size.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + ), size.legend = tm_legend("Population in 2020"), - shape.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22)), + shape.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + ), shape.legend = tm_legend_combine("size")) + tm_labels("name", options = opt_tm_labels(remove.overlap = FALSE)) diff --git a/examples/tm_text.R b/examples/tm_text.R index 84a8f0d9..a7fde07c 100644 --- a/examples/tm_text.R +++ b/examples/tm_text.R @@ -22,14 +22,19 @@ tm_shape(land) + col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), col.legend = tm_legend_hide()) + tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), col = cols4all::c4a("brewer.pastel1")[2]) + -tm_shape(Africa, is.main = TRUE) + + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), + col = cols4all::c4a("brewer.pastel1")[2]) + + tm_shape(Africa, is.main = TRUE) + tm_borders() + -tm_shape(metroAfrica) + + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", - size.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2)), + size.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + ), size.legend = tm_legend("Population in 2020"), - shape.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22)), + shape.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + ), shape.legend = tm_legend_combine("size")) + tm_labels("name") diff --git a/man/tm_cartogram.Rd b/man/tm_cartogram.Rd index 9d28842d..bbb472ee 100644 --- a/man/tm_cartogram.Rd +++ b/man/tm_cartogram.Rd @@ -1,9 +1,18 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/tm_layers_cartogram.R -\name{tm_cartogram} +\name{opt_tm_cartogram} +\alias{opt_tm_cartogram} +\alias{opt_tm_cartogram_ncont} +\alias{opt_tm_cartogram_dorling} \alias{tm_cartogram} \title{Map layer: cartogram} \usage{ +opt_tm_cartogram(type = "cont", itermax = 15, ...) + +opt_tm_cartogram_ncont(type = "ncont", expansion = 1, inplace = FALSE, ...) + +opt_tm_cartogram_dorling(type = "dorling", share = 5, itermax = 1000, ...) + tm_cartogram( size = 1, size.scale = tm_scale(), @@ -11,18 +20,12 @@ tm_cartogram( size.chart = tm_chart_none(), size.free = NA, plot.order = tm_plot_order("size", reverse = FALSE), - trans.args = list(type = "cont", itermax = 15), + options = opt_tm_cartogram(), ... ) } \arguments{ -\item{size, size.scale, size.legend, size.chart, size.free}{Transformation variable that -determines the size of the polygons.} - -\item{plot.order}{Specification in which order the spatial features are drawn. -See \code{\link[=tm_plot_order]{tm_plot_order()}} for details.} - -\item{trans.args}{lists that are passed on to internal transformation function} +\item{type, itermax, expansion, inplace, share}{Additional options} \item{...}{ Arguments passed on to \code{\link[=tm_polygons]{tm_polygons}} @@ -46,7 +49,6 @@ can be switched on and off. Options: \code{"radio"} for radio buttons (meaning only one group can be shown), \code{"check"} for check boxes (so multiple groups can be shown), and \code{"none"} for no control (the group cannot be (de)selected).} - \item{\code{options}}{options passed on to the corresponding \verb{opt_} function} \item{\code{popup.vars}}{names of data variables that are shown in the popups in \code{"view"} mode. Set popup.vars to \code{TRUE} to show all variables in the shape object. Set popup.vars to \code{FALSE} to disable popups. Set \code{popup.vars} @@ -63,6 +65,14 @@ is applied to the named variable.} \item{\code{id}}{name of the data variable that specifies the indices of the spatial features. Only used for \code{"view"} mode.} }} + +\item{size, size.scale, size.legend, size.chart, size.free}{Transformation variable that +determines the size of the polygons.} + +\item{plot.order}{Specification in which order the spatial features are drawn. +See \code{\link[=tm_plot_order]{tm_plot_order()}} for details.} + +\item{options}{options passed on to the corresponding \verb{opt_} function} } \description{ Map layer that draws a cartogram diff --git a/man/tm_shape.Rd b/man/tm_shape.Rd index b097f015..2253b8ae 100644 --- a/man/tm_shape.Rd +++ b/man/tm_shape.Rd @@ -37,3 +37,7 @@ bounding box of the map?} Specify a shape, which is a spatial object from one of these spatial object class packages: \code{\link[sf:sf]{sf}}, \code{\link[stars:st_as_stars]{stars}}, or \code{terra}. } +\examples{ +tm_shape(World, crs = "+proj=robin", filter = World$continent=="Africa") + + tm_polygons() +} diff --git a/man/tm_symbols.Rd b/man/tm_symbols.Rd index e52c2eb0..ada96755 100644 --- a/man/tm_symbols.Rd +++ b/man/tm_symbols.Rd @@ -5,7 +5,6 @@ \alias{opt_tm_dots} \alias{opt_tm_bubbles} \alias{opt_tm_squares} -\alias{opt_tm_sqaures} \alias{tm_symbols} \alias{tm_dots} \alias{tm_bubbles} @@ -33,7 +32,7 @@ opt_tm_bubbles( grob.dim = c(width = 48, height = 48, render.width = 256, render.height = 256) ) -opt_tm_sqaures( +opt_tm_squares( points.only = "ifany", icon.scale = 3, just = NA, @@ -192,7 +191,7 @@ tm_squares( zindex = NA, group = NA, group.control = "check", - options = opt_tm_sqaures(), + options = opt_tm_squares(), ... ) } @@ -298,17 +297,24 @@ Africa = World[World$continent == "Africa", ] tm_shape(land) + tm_raster("cover_cls", - col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), + col.scale = tm_scale( + values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)] + ), col.legend = tm_legend_hide()) + tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), col = cols4all::c4a("brewer.pastel1")[2]) + + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), + col = cols4all::c4a("brewer.pastel1")[2]) + tm_shape(Africa, is.main = TRUE) + tm_borders() + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", - size.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2)), + size.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + ), size.legend = tm_legend("Population in 2020"), - shape.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22)), + shape.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + ), shape.legend = tm_legend_combine("size")) + tm_labels("name", options = opt_tm_labels(remove.overlap = FALSE)) diff --git a/man/tm_text.Rd b/man/tm_text.Rd index 3cc16b93..82c59f0f 100644 --- a/man/tm_text.Rd +++ b/man/tm_text.Rd @@ -168,7 +168,6 @@ tm_labels( angle.legend = tm_legend_hide(), angle.chart = tm_chart_none(), angle.free = NA, - shadow = FALSE, plot.order = tm_plot_order("AREA", reverse = FALSE, na.order = "bottom"), zindex = NA, group = NA, @@ -372,14 +371,19 @@ tm_shape(land) + col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), col.legend = tm_legend_hide()) + tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), col = cols4all::c4a("brewer.pastel1")[2]) + -tm_shape(Africa, is.main = TRUE) + + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), + col = cols4all::c4a("brewer.pastel1")[2]) + + tm_shape(Africa, is.main = TRUE) + tm_borders() + -tm_shape(metroAfrica) + + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", - size.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2)), + size.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + ), size.legend = tm_legend("Population in 2020"), - shape.scale = tm_scale_intervals(breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22)), + shape.scale = tm_scale_intervals( + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + ), shape.legend = tm_legend_combine("size")) + tm_labels("name") From 93b666578650cafe973bb399e88f7ca848398e6f Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 16:21:16 -0400 Subject: [PATCH 3/7] Improve error message for `id` and `label`. similar to what I did for `popup.vars` in #817 --- R/misc_other.R | 8 ++++---- R/step1_helper_facets.R | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/misc_other.R b/R/misc_other.R index d543cc82..5ad41639 100644 --- a/R/misc_other.R +++ b/R/misc_other.R @@ -395,7 +395,7 @@ native_to_npc_to_native <- function(x, scale) { } } - xy <- xy.coords(x, y, recycle = TRUE) + xy <- grDevices::xy.coords(x, y, recycle = TRUE) z <- toUnityCoords(xy) x2 <- z$x y2 <- z$y @@ -434,10 +434,10 @@ native_to_npc_to_native <- function(x, scale) { #w2 <- w + (h-w) * abs(cos(angles*pi/180)) #h2 <- h + (w-h) * abs(sin(angles*pi/180)) - z2 <- xy.coords(xs2, ys2, recycle = TRUE) + z2 <- grDevices::xy.coords(xs2, ys2, recycle = TRUE) xy2 <- toUserCoords(z2) - list(poly=polygonGrob(unit(xy2$x, "native"), unit(xy2$y, "native"), id=id, gp=rg$gp)) + list(poly=polygonGrob(unit(xy2$x, "native"), grid::unit(xy2$y, "native"), id=id, gp=rg$gp)) #list(poly=rectGrob(unit(x, "native"), unit(y, "native"), width = unit(w, "native"), height=unit(h, "native"), gp = rg$gp)) } @@ -454,7 +454,7 @@ native_to_npc_to_native <- function(x, scale) { .editGrob <- function(tg, sel, shiftX, shiftY, angles) { nt <- length(sel) angles <- rep(angles, length.out=nt) - if (any(angles!=0)) { + if (any(angles != 0)) { if (inherits(tg, "rect")) { tg <- .rectGrob2pathGrob(tg, angles)$poly } diff --git a/R/step1_helper_facets.R b/R/step1_helper_facets.R index bfa8c814..4a26fa8c 100644 --- a/R/step1_helper_facets.R +++ b/R/step1_helper_facets.R @@ -177,9 +177,9 @@ step1_rearrange_facets = function(tmo, o) { } if (length(popup.vars)) add_used_vars(popup.vars) - if (hover != "" && !hover %in% smeta$vars) stop("Incorrect hover label", call. = FALSE) + if (hover != "" && !hover %in% smeta$vars) rlang::arg_match0(hover, smeta$vars, "hover label", error_call = NULL) if (hover != "") add_used_vars(hover) - if (id != "" && !id %in% smeta$vars) stop("Incorrect id", call. = FALSE) + if (id != "" && !id %in% smeta$vars) rlang::arg_match0(id, smeta$vars, arg_nm = "id", error_call = NULL) if (id != "") add_used_vars(id) }) }) From 3d342aabe5faddb1aeda12dd7675ccd9c74fd3a7 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 16:58:42 -0400 Subject: [PATCH 4/7] Other example widths issues --- examples/tm_lines.R | 9 ++++++--- examples/tm_symbols.R | 13 +++++++------ examples/tm_text.R | 10 +++++++--- man/tm_lines.Rd | 9 ++++++--- man/tm_symbols.Rd | 13 +++++++------ man/tm_text.Rd | 10 +++++++--- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/examples/tm_lines.R b/examples/tm_lines.R index edee6c03..31c344b1 100644 --- a/examples/tm_lines.R +++ b/examples/tm_lines.R @@ -1,9 +1,12 @@ tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = 0.2, value.neutral = 2), - col = "scalerank", col.scale = tm_scale_categorical(values = "seaborn.dark")) + tm_lines(lwd = "strokelwd", + lwd.scale = tm_scale_asis(values.scale = 0.2, value.neutral = 2), + col = "scalerank", + col.scale = tm_scale_categorical(values = "seaborn.dark")) tm_shape(World) + - tm_lines(col = "continent", col.scale = tm_scale_categorical(values = "seaborn.dark"), + tm_lines(col = "continent", + col.scale = tm_scale_categorical(values = "seaborn.dark"), lty = "continent", lwd = 1.5, lty.legend = tm_legend_combine("col")) diff --git a/examples/tm_symbols.R b/examples/tm_symbols.R index 98a63359..8cc66762 100644 --- a/examples/tm_symbols.R +++ b/examples/tm_symbols.R @@ -19,7 +19,8 @@ tm_shape(land) + ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values = c(21, 23, 22, 21, 23, 22) ), shape.legend = tm_legend_combine("size")) + tm_labels("name", options = opt_tm_labels(remove.overlap = FALSE)) @@ -98,7 +99,7 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & grobs2 = grobs grobs2[[6]] = 21 - + names(grobs2) <- as.character(NLD_prov$name) NLD_prov$population[1:5] = 500000 tm_shape(NLD_prov) + tm_polygons(group = "Provinces") + @@ -141,10 +142,10 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & geom_point(aes(x=p%%16, y=-(p%/%16), shape=p), size=5, fill="red") + geom_text(mapping=aes(x=p%%16, y=-(p%/%16+0.25), label=p), size=3) + scale_shape_identity() + - theme(axis.title=element_blank(), - axis.text=element_blank(), - axis.ticks=element_blank(), - panel.background=element_blank()) + theme(axis.title = element_blank(), + axis.text = element_blank(), + axis.ticks = element_blank(), + panel.background = element_blank()) } } diff --git a/examples/tm_text.R b/examples/tm_text.R index a7fde07c..cba4be5a 100644 --- a/examples/tm_text.R +++ b/examples/tm_text.R @@ -9,7 +9,8 @@ metro$upside_down = ifelse(sf::st_coordinates(metro)[,2] < 0, 180, 0) tm_shape(metro) + tm_text(text = "name", size = "pop2020", angle = "upside_down", size.legend = tm_legend_hide(), - col = "upside_down", col.scale = tm_scale_categorical(values = c("#9900BB", "#228822")), + col = "upside_down", + col.scale = tm_scale_categorical(values = c("#9900BB", "#228822")), col.legend = tm_legend_hide()) + tm_title_out("Which Hemisphere?", position = tm_pos_out("center", "top", pos.v = "bottom")) @@ -19,7 +20,9 @@ Africa = World[World$continent == "Africa", ] tm_shape(land) + tm_raster("cover_cls", - col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), + col.scale = tm_scale( + values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)] + ), col.legend = tm_legend_hide()) + tm_shape(rivers) + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), @@ -33,7 +36,8 @@ tm_shape(rivers) + ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values = c(21, 23, 22, 21, 23, 22) ), shape.legend = tm_legend_combine("size")) + tm_labels("name") diff --git a/man/tm_lines.Rd b/man/tm_lines.Rd index 4d0c4b76..6dfe3b4f 100644 --- a/man/tm_lines.Rd +++ b/man/tm_lines.Rd @@ -105,11 +105,14 @@ so the \verb{*.free} argument requires only one logical value. } \examples{ tm_shape(rivers) + - tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = 0.2, value.neutral = 2), - col = "scalerank", col.scale = tm_scale_categorical(values = "seaborn.dark")) + tm_lines(lwd = "strokelwd", + lwd.scale = tm_scale_asis(values.scale = 0.2, value.neutral = 2), + col = "scalerank", + col.scale = tm_scale_categorical(values = "seaborn.dark")) tm_shape(World) + - tm_lines(col = "continent", col.scale = tm_scale_categorical(values = "seaborn.dark"), + tm_lines(col = "continent", + col.scale = tm_scale_categorical(values = "seaborn.dark"), lty = "continent", lwd = 1.5, lty.legend = tm_legend_combine("col")) diff --git a/man/tm_symbols.Rd b/man/tm_symbols.Rd index ada96755..70592682 100644 --- a/man/tm_symbols.Rd +++ b/man/tm_symbols.Rd @@ -313,7 +313,8 @@ tm_shape(land) + ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values = c(21, 23, 22, 21, 23, 22) ), shape.legend = tm_legend_combine("size")) + tm_labels("name", options = opt_tm_labels(remove.overlap = FALSE)) @@ -392,7 +393,7 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & grobs2 = grobs grobs2[[6]] = 21 - + names(grobs2) <- as.character(NLD_prov$name) NLD_prov$population[1:5] = 500000 tm_shape(NLD_prov) + tm_polygons(group = "Provinces") + @@ -435,10 +436,10 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & geom_point(aes(x=p\%\%16, y=-(p\%/\%16), shape=p), size=5, fill="red") + geom_text(mapping=aes(x=p\%\%16, y=-(p\%/\%16+0.25), label=p), size=3) + scale_shape_identity() + - theme(axis.title=element_blank(), - axis.text=element_blank(), - axis.ticks=element_blank(), - panel.background=element_blank()) + theme(axis.title = element_blank(), + axis.text = element_blank(), + axis.ticks = element_blank(), + panel.background = element_blank()) } } diff --git a/man/tm_text.Rd b/man/tm_text.Rd index 82c59f0f..77f49730 100644 --- a/man/tm_text.Rd +++ b/man/tm_text.Rd @@ -358,7 +358,8 @@ metro$upside_down = ifelse(sf::st_coordinates(metro)[,2] < 0, 180, 0) tm_shape(metro) + tm_text(text = "name", size = "pop2020", angle = "upside_down", size.legend = tm_legend_hide(), - col = "upside_down", col.scale = tm_scale_categorical(values = c("#9900BB", "#228822")), + col = "upside_down", + col.scale = tm_scale_categorical(values = c("#9900BB", "#228822")), col.legend = tm_legend_hide()) + tm_title_out("Which Hemisphere?", position = tm_pos_out("center", "top", pos.v = "bottom")) @@ -368,7 +369,9 @@ Africa = World[World$continent == "Africa", ] tm_shape(land) + tm_raster("cover_cls", - col.scale = tm_scale(values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]), + col.scale = tm_scale( + values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)] + ), col.legend = tm_legend_hide()) + tm_shape(rivers) + tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3), @@ -382,7 +385,8 @@ tm_shape(rivers) + ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values = c(21, 23, 22, 21, 23, 22) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values = c(21, 23, 22, 21, 23, 22) ), shape.legend = tm_legend_combine("size")) + tm_labels("name") From 8f3afb22a32aff5881c863e62d64fd1354a229d1 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 16:58:59 -0400 Subject: [PATCH 5/7] Fix partial match --- R/misc_pointLabel.R | 2 +- R/tmapChart.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/misc_pointLabel.R b/R/misc_pointLabel.R index da141681..f4f2d09c 100644 --- a/R/misc_pointLabel.R +++ b/R/misc_pointLabel.R @@ -117,7 +117,7 @@ pointLabel2 <- function (x, y, width, height, bbx, rectv <- width + (0+1i) * height rectidx1 <- rectidx2 <- array(0, (length(x)^2 - length(x))/2) k <- 0 - for (i in 1:length(x)) for (j in seq(len = (i - 1))) { + for (i in 1:length(x)) for (j in seq_len(i - 1)) { k <- k + 1 rectidx1[k] <- i rectidx2[k] <- j diff --git a/R/tmapChart.R b/R/tmapChart.R index 9a1ad086..d83858be 100644 --- a/R/tmapChart.R +++ b/R/tmapChart.R @@ -102,7 +102,7 @@ bin_num = function(x1, breaks_def, chart) { # are breaks (and bin_colors) predefined = !is.null(breaks_def) - if (is.null(chart$breaks)) { + if (is.null(chart$breaks_def)) { if (!predefined) { breaks = pretty(x1) ids = rep(1L, length(breaks) - 1) @@ -112,7 +112,7 @@ bin_num = function(x1, breaks_def, chart) { ids = 1L:(length(breaks) - 1L) } } else { - breaks = chart$breaks + breaks = chart$breaks_def subbreaks = (all(breaks_def %in% breaks)) break_mids = (breaks[-1] + head(breaks, -1)) / 2 From d3bfa69a6da2aae1faf4708d91ba3def1594f69f Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 16:59:43 -0400 Subject: [PATCH 6/7] [partial match] change all co.x.lns -> co.x and all co.y.lns -> co.y to avoid partial matching warnings. --- R/tmapGridAux.R | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/R/tmapGridAux.R b/R/tmapGridAux.R index 786e62a8..b0a23032 100644 --- a/R/tmapGridAux.R +++ b/R/tmapGridAux.R @@ -266,7 +266,8 @@ tmapGridGridPrep = function(a, bs, id, o) { x2 <- x2[!lnsX_emp] lnsX_proj <- lnsX_proj[!lnsX_emp] xco <- st_coordinates(lnsX_proj) - co.x.lns <- lapply(unique(xco[,3]), function(i) { + # co.x.lns + co.x <- lapply(unique(xco[,3]), function(i) { lco <- xco[xco[,3]==i, 1:2] lco[, 1] <- (lco[, 1]-bbx_orig[1]) / (bbx_orig[3] - bbx_orig[1]) lco[, 2] <- (lco[, 2]-bbx_orig[2]) / (bbx_orig[4] - bbx_orig[2]) @@ -278,7 +279,7 @@ tmapGridGridPrep = function(a, bs, id, o) { sel.x <- which(x2 %in% x) } else { - co.x.lns <- numeric(0) + co.x <- numeric(0) } if (lnsSel[2]) { @@ -291,7 +292,7 @@ tmapGridGridPrep = function(a, bs, id, o) { y2 <- y2[!lnsY_emp] lnsY_proj <- lnsY_proj[!lnsY_emp] yco <- st_coordinates(lnsY_proj) - co.y.lns <- lapply(unique(yco[,3]), function(i) { + co.y <- lapply(unique(yco[,3]), function(i) { lco <- yco[yco[,3]==i, 1:2] lco[, 1] <- (lco[, 1]-bbx_orig[1]) / (bbx_orig[3] - bbx_orig[1]) lco[, 2] <- (lco[, 2]-bbx_orig[2]) / (bbx_orig[4] - bbx_orig[2]) @@ -303,7 +304,7 @@ tmapGridGridPrep = function(a, bs, id, o) { sel.y <- which(y2 %in% y) } else { - co.y.lns <- numeric(0) + co.y <- numeric(0) } @@ -396,7 +397,7 @@ tmapGridGridXLab = function(bi, bbx, facet_row, facet_col, facet_page, o) { # find coordinates for projected grid labels if (!is.na(a$crs)) { - glabelsx <- get_gridline_labels(lco=a$co.x.lns[a$sel.x], xax = as.integer(is_top)) + glabelsx <- get_gridline_labels(lco=a$co.x[a$sel.x], xax = as.integer(is_top)) cogridx <- glabelsx$cogrid idsx <- glabelsx$ids labelsx <- labelsx[idsx] @@ -473,7 +474,7 @@ tmapGridGridYLab = function(bi, bbx, facet_row, facet_col, facet_page, o) { # find coordinates for projected grid labels if (!is.na(a$crs)) { - glabelsy <- get_gridline_labels(lco=a$co.y.lns[a$sel.y], yax = 0) + glabelsy <- get_gridline_labels(lco=a$co.y[a$sel.y], yax = 0) cogridy <- glabelsy$cogrid idsy <- glabelsy$ids labelsy <- labelsy[idsy] @@ -603,7 +604,7 @@ tmapGridGrid = function(bi, bbx, facet_row, facet_col, facet_page, id, pane, gro # find coordinates for projected grid labels if (!is.na(a$crs)) { if (selx) { - glabelsx <- get_gridline_labels(lco=a$co.x.lns[a$sel.x], xax = labelsXw + spacerX+marginX) + glabelsx <- get_gridline_labels(lco=a$co.x[a$sel.x], xax = labelsXw + spacerX+marginX) cogridx <- glabelsx$cogrid idsx <- glabelsx$ids labelsx <- labelsx[idsx] @@ -614,7 +615,7 @@ tmapGridGrid = function(bi, bbx, facet_row, facet_col, facet_page, id, pane, gro # } if (sely) { - glabelsy <- get_gridline_labels(lco=a$co.y.lns[a$sel.y], yax = labelsYw + spacerY+marginY) + glabelsy <- get_gridline_labels(lco=a$co.y[a$sel.y], yax = labelsYw + spacerY+marginY) cogridy <- glabelsy$cogrid idsy <- glabelsy$ids labelsy <- labelsy[idsy] @@ -647,13 +648,13 @@ tmapGridGrid = function(bi, bbx, facet_row, facet_col, facet_page, id, pane, gro # crop projected grid lines, and extract polylineGrob ingredients if (!is.na(a$crs)) { lnsList <- list( - if (any(selx)) st_multilinestring(a$co.x.lns) else NULL, - if (any(sely)) st_multilinestring(a$co.y.lns) else NULL + if (any(selx)) st_multilinestring(a$co.x) else NULL, + if (any(sely)) st_multilinestring(a$co.y) else NULL ) lnsSel <- !vapply(lnsList, is.null, logical(1)) if (!any(lnsSel)) { - grid.co.x.lns <- numeric(0) - grid.co.y.lns <- numeric(0) + grid.co.x <- numeric(0) + grid.co.y <- numeric(0) } else { lns <- st_sf(ID=c("x", "y")[lnsSel], geometry = st_sfc(lnsList[lnsSel], crs = 4326)) # trick for 0-1 coordinates sf_bbox <- tmaptools::bb_poly(bb(c(labelsYw + spacerY + marginY, labelsXw + spacerX + marginX, 1, 1)), projection = 4326) From 2233878f1a90adaf279319fbeebc310ed0ef25bf Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 28 Mar 2024 17:13:37 -0400 Subject: [PATCH 7/7] wrap lines [ci skip] --- examples/tm_symbols.R | 3 ++- examples/tm_text.R | 3 ++- man/tm_symbols.Rd | 3 ++- man/tm_text.Rd | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/tm_symbols.R b/examples/tm_symbols.R index 8cc66762..9887d4c7 100644 --- a/examples/tm_symbols.R +++ b/examples/tm_symbols.R @@ -15,7 +15,8 @@ tm_shape(land) + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", size.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values.range = c(0.2,2) ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( diff --git a/examples/tm_text.R b/examples/tm_text.R index cba4be5a..041a3662 100644 --- a/examples/tm_text.R +++ b/examples/tm_text.R @@ -32,7 +32,8 @@ tm_shape(rivers) + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", size.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values.range = c(0.2,2) ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( diff --git a/man/tm_symbols.Rd b/man/tm_symbols.Rd index 70592682..a3cc7203 100644 --- a/man/tm_symbols.Rd +++ b/man/tm_symbols.Rd @@ -309,7 +309,8 @@ tm_shape(land) + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", size.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values.range = c(0.2,2) ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals( diff --git a/man/tm_text.Rd b/man/tm_text.Rd index 77f49730..60ad3583 100644 --- a/man/tm_text.Rd +++ b/man/tm_text.Rd @@ -381,7 +381,8 @@ tm_shape(rivers) + tm_shape(metroAfrica) + tm_symbols(fill = "red", shape = "pop2020", size = "pop2020", size.scale = tm_scale_intervals( - breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, values.range = c(0.2,2) + breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6, + values.range = c(0.2,2) ), size.legend = tm_legend("Population in 2020"), shape.scale = tm_scale_intervals(