From 378f421bf5f70000ae2e10006650d5b7f598e533 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 15 Mar 2024 09:33:54 -0400 Subject: [PATCH 1/4] address notes --- R/global-variables.R | 3 ++- R/tm_layers_text.R | 2 ++ R/v4-not-implemented.R | 12 +++++++--- examples/tm_chart.R | 49 ++++++++++++++++++++++------------------ examples/tm_text.R | 6 +++-- man/tm_chart.Rd | 49 ++++++++++++++++++++++------------------ man/tm_text.Rd | 23 +++++++++++++++++++ man/v4-not-yet.Rd | 51 ++++++++++++++++++++++++++++++++++++++++++ vignettes/tmap_vv.Rmd | 10 ++++----- 9 files changed, 150 insertions(+), 55 deletions(-) create mode 100644 man/v4-not-yet.Rd diff --git a/R/global-variables.R b/R/global-variables.R index c6f7aa2d..0f939b65 100644 --- a/R/global-variables.R +++ b/R/global-variables.R @@ -30,5 +30,6 @@ utils::globalVariables(c( "legend.bg.alpha", "lin", "m", "n", "overlays_tiles", "show", "show.labels", "show.warnings", "total", "trans.args", "type", "values", "xlab.rotation", "xlab.show", "xlab.side", "xlab.space", "xlab.text", "ylab.rotation", - "ylab.show", "ylab.side", "ylab.space", "ylab.text", "z" + "ylab.show", "ylab.side", "ylab.space", "ylab.text", "z", + "x", "y", "color", "freq", "bin", "bin1", "bin2" )) diff --git a/R/tm_layers_text.R b/R/tm_layers_text.R index 9d6f0c0e..0745e09f 100644 --- a/R/tm_layers_text.R +++ b/R/tm_layers_text.R @@ -60,6 +60,8 @@ #' @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 Transformations +#' variables that determine the angle of the text #' @param ... to catch deprecated arguments from version < 4.0 #' @example ./examples/tm_text.R #' @export diff --git a/R/v4-not-implemented.R b/R/v4-not-implemented.R index ac0157f3..d7082867 100644 --- a/R/v4-not-implemented.R +++ b/R/v4-not-implemented.R @@ -1,11 +1,17 @@ +#' Features not yet implemented in tmap4 +#' +#' @param ... Arguments +#' @name v4-not-yet +NULL + #' @export #' @rdname v4-not-yet -tm_iso <- function() { +tm_iso <- function(...) { stop("Not yet implemented in v4") } #' @export #' @rdname v4-not-yet -tm_markers <- function() { +tm_markers <- function(...) { stop("Not yet implemented in v4") } #' @export @@ -15,7 +21,7 @@ tm_logo <- function(...) { } #' @export #' @rdname v4-not-yet -tm_minimap <- function() { +tm_minimap <- function(...) { stop("Not yet implemented in v4") } #' @export diff --git a/examples/tm_chart.R b/examples/tm_chart.R index 612d8d5b..ea5f358d 100644 --- a/examples/tm_chart.R +++ b/examples/tm_chart.R @@ -1,36 +1,41 @@ ## numerical variable tm_shape(World) + - tm_polygons ("HPI", + tm_polygons("HPI", fill.scale = tm_scale_intervals(), fill.chart = tm_chart_histogram()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_continuous(), - fill.chart = tm_chart_histogram(position = tm_pos_out("center", "bottom"), width = 30)) + tm_polygons("HPI", + fill.scale = tm_scale_continuous(), + fill.chart = tm_chart_histogram( + position = tm_pos_out("center", "bottom"), + width = 30) + ) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_donut()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_donut()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_box()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_box()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_violin()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_violin()) # with additional ggplot2 code require(ggplot2) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_bar(extra.ggplot2 = theme(panel.grid.major.y = element_line(colour = "red")))) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_bar( + extra.ggplot2 = theme(panel.grid.major.y = element_line(colour = "red"))) + ) tm_shape(land) + tm_raster("trees", @@ -38,14 +43,14 @@ tm_shape(land) + ## categorical variable tm_shape(World) + - tm_polygons ("economy", - fill.scale = tm_scale_categorical(), - fill.chart = tm_chart_bar()) + tm_polygons("economy", + fill.scale = tm_scale_categorical(), + fill.chart = tm_chart_bar()) tm_shape(World) + - tm_polygons ("economy", - fill.scale = tm_scale_categorical(), - fill.chart = tm_chart_donut()) + tm_polygons("economy", + fill.scale = tm_scale_categorical(), + fill.chart = tm_chart_donut()) # bivariate (in development) tm_shape(World) + diff --git a/examples/tm_text.R b/examples/tm_text.R index 105d816b..cd09ee2b 100644 --- a/examples/tm_text.R +++ b/examples/tm_text.R @@ -30,9 +30,11 @@ tm_shape(metro) + tm_shape(World) + tm_polygons() + tm_shape(metro) + - tm_text(text = "name", size = "pop2020", angle = -30, shadow = TRUE) + tm_text(text = "name", size = "pop2020", + angle = -30, shadow = TRUE) 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()) + tm_text(text = "name", size = "pop2020", + angle = "upside_down", size.legend = tm_legend_hide()) diff --git a/man/tm_chart.Rd b/man/tm_chart.Rd index e24fec9d..3d87ed13 100644 --- a/man/tm_chart.Rd +++ b/man/tm_chart.Rd @@ -94,36 +94,41 @@ Note that these charts are different from charts drawn inside the map. Those are ## numerical variable tm_shape(World) + - tm_polygons ("HPI", + tm_polygons("HPI", fill.scale = tm_scale_intervals(), fill.chart = tm_chart_histogram()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_continuous(), - fill.chart = tm_chart_histogram(position = tm_pos_out("center", "bottom"), width = 30)) + tm_polygons("HPI", + fill.scale = tm_scale_continuous(), + fill.chart = tm_chart_histogram( + position = tm_pos_out("center", "bottom"), + width = 30) + ) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_donut()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_donut()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_box()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_box()) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_violin()) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_violin()) # with additional ggplot2 code require(ggplot2) tm_shape(World) + - tm_polygons ("HPI", - fill.scale = tm_scale_intervals(), - fill.chart = tm_chart_bar(extra.ggplot2 = theme(panel.grid.major.y = element_line(colour = "red")))) + tm_polygons("HPI", + fill.scale = tm_scale_intervals(), + fill.chart = tm_chart_bar( + extra.ggplot2 = theme(panel.grid.major.y = element_line(colour = "red"))) + ) tm_shape(land) + tm_raster("trees", @@ -131,14 +136,14 @@ tm_shape(land) + ## categorical variable tm_shape(World) + - tm_polygons ("economy", - fill.scale = tm_scale_categorical(), - fill.chart = tm_chart_bar()) + tm_polygons("economy", + fill.scale = tm_scale_categorical(), + fill.chart = tm_chart_bar()) tm_shape(World) + - tm_polygons ("economy", - fill.scale = tm_scale_categorical(), - fill.chart = tm_chart_donut()) + tm_polygons("economy", + fill.scale = tm_scale_categorical(), + fill.chart = tm_chart_donut()) # bivariate (in development) tm_shape(World) + diff --git a/man/tm_text.Rd b/man/tm_text.Rd index e8783d9a..c8ee2fd5 100644 --- a/man/tm_text.Rd +++ b/man/tm_text.Rd @@ -51,6 +51,11 @@ tm_text( 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, shadow = FALSE, plot.order = tm_plot_order("AREA", reverse = FALSE, na.order = "bottom"), trans.args = list(points.only = "ifany"), @@ -90,6 +95,9 @@ the background color transparency. See Details.} \item{ymod, ymod.scale, ymod.legend, ymod.chart, ymod.free}{Transformation variable that determines the y offset. See details. the text. See details.} +\item{angle, angle.scale, angle.legend, angle.chart, angle.free}{Transformations +variables that determine the angle of the text} + \item{shadow}{Shadow behind the text. Logical or color.} \item{plot.order}{Specification in which order the spatial features are drawn. @@ -160,6 +168,9 @@ tm_shape(World) + bgcol_alpha = "pop_est", bgcol_alpha.scale = tm_scale_intervals(style = "kmeans")) +tm_shape(metro) + + tm_text(text = "name", size = "pop2020", size.legend = tm_legend_hide()) + ## xymod metro$initial = substr(metro$name,1,1) metro$az = (match(metro$initial, LETTERS)-1) /25 @@ -168,4 +179,16 @@ tm_shape(metro) + tm_dots("red") + tm_text("initial", ymod = "az") +# angle +tm_shape(World) + + tm_polygons() + +tm_shape(metro) + + tm_text(text = "name", size = "pop2020", + angle = -30, shadow = TRUE) + +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()) + } diff --git a/man/v4-not-yet.Rd b/man/v4-not-yet.Rd new file mode 100644 index 00000000..2f6df3d2 --- /dev/null +++ b/man/v4-not-yet.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/v4-not-implemented.R +\name{v4-not-yet} +\alias{v4-not-yet} +\alias{tm_iso} +\alias{tm_markers} +\alias{tm_logo} +\alias{tm_minimap} +\alias{tmap_grob} +\alias{tmapOutput} +\alias{tmapProxy} +\alias{renderTmap} +\alias{tm_remove_layer} +\alias{tm_rgba} +\alias{tmap_tip} +\alias{tmap_style_catalog} +\alias{tmap_style_catalogue} +\title{Features not yet implemented in tmap4} +\usage{ +tm_iso(...) + +tm_markers(...) + +tm_logo(...) + +tm_minimap(...) + +tmap_grob(...) + +tmapOutput(...) + +tmapProxy(...) + +renderTmap(...) + +tm_remove_layer(...) + +tm_rgba(...) + +tmap_tip(...) + +tmap_style_catalog(...) + +tmap_style_catalogue(...) +} +\arguments{ +\item{...}{Arguments} +} +\description{ +Features not yet implemented in tmap4 +} diff --git a/vignettes/tmap_vv.Rmd b/vignettes/tmap_vv.Rmd index d47e9bc9..f73e483d 100644 --- a/vignettes/tmap_vv.Rmd +++ b/vignettes/tmap_vv.Rmd @@ -12,7 +12,7 @@ output: link-citations: yes vignette: > \usepackage[utf8]{inputenc} - %\VignetteIndexEntry{tmap: visual variables} + %\VignetteIndexEntry{tmap: charts} %\VignetteEngine{knitr::rmarkdown} editor_options: chunk_output_type: console @@ -31,9 +31,9 @@ data(World, metro, rivers, land) ## Introduction -**tmap** is an R package for spatial data visualization. This vignette describes the alpha version of the major update (version 4), which will be on CRAN in the course of 2023. +**tmap** is an R package for spatial data visualization. This vignette describes the alpha version of the major update (version 4), which will be on CRAN in the course of 2024. -#### tmap 4 - tmap 3.x +### tmap 4 - tmap 3.x * **tmap 3.x** supports several map layer variables, for example `"col"`, `"size"`, and `"shape"` for the `tm_symbols()` map layer function. There will be many more of those variables in **tmap 4**. Besides the visual variables, so-called transformation variables also will be available. A *transformation variable* role is to change the spatial coordinates (for instance, to create a cartogram). A *visual variable* only changes the appearance of a spatial object, e.g. fill color or line width. You can find some examples of these variables below. @@ -51,7 +51,7 @@ data(World, metro, rivers, land) * It is possible to combine legends, which is useful if the same data variable is applied for multiple visual variables using the same scaling function. -#### tmap 4 - ggplot2 +### tmap 4 - ggplot2 The **tmap** package is very similar to **ggplot2** and its Grammar of Graphics, but tailored to spatial data visualization, whereas **ggplot2** is much more general. More specifically: @@ -65,7 +65,7 @@ The **tmap** package is very similar to **ggplot2** and its Grammar of Graphics, * ... -#### tmap 4 - other R packages +### tmap 4 - other R packages There are several great R packages for spatial data visualization, including: **ggplot2**, **mapview**, **leaflet**, **mapsf**, and the generic plot function. From b0d68a28449e5a652d40bec428d48018a2efdaf6 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 15 Mar 2024 09:39:51 -0400 Subject: [PATCH 2/4] increment version [ci skip] --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bdd23ed6..40e1e421 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tmap Title: Thematic Maps -Version: 3.99.9000 +Version: 3.99.9001 Authors@R: c( person("Martijn", "Tennekes", , "mtennekes@gmail.com", role = c("aut", "cre")), person("Jakub", "Nowosad", , "nowosad.jakub@gmail.com", role = "ctb"), @@ -25,7 +25,7 @@ Depends: R (>= 3.5.0) Imports: classInt (>= 0.4-3), - cols4all (>= 0.7), + cols4all (>= 0.7-1), data.table, grid, htmltools, From d4e583cd4b06b634fd2a626e2785f5fe77651c1d Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 15 Mar 2024 10:05:31 -0400 Subject: [PATCH 3/4] Add a leaflet to avoid ugly failure with view mode. --- NAMESPACE | 1 + R/tmapLeafletComp_charts.R | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 574df8a3..3852569b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -92,6 +92,7 @@ S3method(tmapLeafletCompWidth,tm_legend_standard_portrait) S3method(tmapLeafletCompWidth,tm_mouse_coordinates) S3method(tmapLeafletCompWidth,tm_scalebar) S3method(tmapLeafletCompWidth,tm_title) +S3method(tmapLeafletLegPlot,tm_chart) S3method(tmapLeafletLegPlot,tm_chart_histogram) S3method(tmapLeafletLegPlot,tm_compass) S3method(tmapLeafletLegPlot,tm_credits) diff --git a/R/tmapLeafletComp_charts.R b/R/tmapLeafletComp_charts.R index 9d75299b..c42a0c38 100644 --- a/R/tmapLeafletComp_charts.R +++ b/R/tmapLeafletComp_charts.R @@ -29,3 +29,8 @@ tmapLeafletCompHeight.tm_chart = function(comp, o) { tmapLeafletLegPlot.tm_chart_histogram = function(comp, lf, o) { lf } +#' @method tmapLeafletLegPlot tm_chart +#' @export +tmapLeafletLegPlot.tm_chart = function(comp, lf, o) { + lf +} From 3db248f2d79a635fd4a58dd2a37b23b00cfe1612 Mon Sep 17 00:00:00 2001 From: olivroy Date: Fri, 15 Mar 2024 10:06:04 -0400 Subject: [PATCH 4/4] Fix partial match warning --- R/step4_plot.R | 2 +- R/tmapLeafletLegend.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/step4_plot.R b/R/step4_plot.R index 7ce535a6..6ce0d8c2 100644 --- a/R/step4_plot.R +++ b/R/step4_plot.R @@ -524,7 +524,7 @@ step4_plot = function(tm, vp, return.asp, show, knit, args) { # prepare aux layers and return group label (in case it is not user specified) aux_group_def = mapply(function(a, id) { FUNaux_prep = paste0("tmap", gs, a$mapping.fun, "Prep") - do.call(FUNaux_prep, list(a = a$args, b = db$bbox, id = id, o = o)) + do.call(FUNaux_prep, list(a = a$args, bs = db$bbox, id = id, o = o)) }, aux, 1:length(aux)) aux_group = mapply(function(a, agd) { if (is.na(a$group)) agd else as.character(a$group) diff --git a/R/tmapLeafletLegend.R b/R/tmapLeafletLegend.R index b3569f5b..defd1583 100644 --- a/R/tmapLeafletLegend.R +++ b/R/tmapLeafletLegend.R @@ -104,7 +104,7 @@ tmapLeaflet_legend = function(cmp, lf, o, orientation) { legpos = leaflet_pos(cmp$position) - lf2 = if (cmp$typ == "none") { + lf2 = if (cmp$type == "none") { #message("Text based legends not supported in view mode") lf } else if (cmp$type == "gradient") {