Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 23, 2024
1 parent 6a1f150 commit f9dc4bb
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 314 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ Suggests:
terra,
testthat (>= 3.2.0),
tidyr
VignetteBuilder:
knitr
Config/Needs/check: Nowosad/spDataLarge, lwgeom
Config/Needs/coverage: Nowosad/spDataLarge, lwgeom
Config/testthat/edition: 3
Expand Down
30 changes: 14 additions & 16 deletions R/pkg.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
#' This package offers a flexible, layer-based, and easy to use approach to create
#' thematic maps, such as choropleths and bubble maps. It is based on the grammar
#' of graphics, and resembles the syntax of ggplot2.
#'
#'
#' This page provides a brief overview of all package functions.
#' See `vignette("tmap_sneak_peek")` for a short introduction with examples.
#'
#' @section Quick plotting method:
#' \tabular{ll}{
Expand All @@ -19,7 +18,7 @@
#' \tabular{ll}{
#' [tm_shape()]\tab Specify a shape object \cr
#' }
#'
#'
#' Aesthetics base layers:
#' \tabular{ll}{
#' [tm_polygons()]\tab Create a polygon layer (with borders) \cr
Expand All @@ -30,7 +29,7 @@
#' [tm_basemap()]\tab Create a layer of basemap tiles \cr
#' [tm_tiles()]\tab Create a layer of overlay tiles \cr
#' }
#'
#'
#' Aesthetics derived layers:
#' \tabular{ll}{
#' [tm_fill()]\tab Create a polygon layer (without borders) \cr
Expand All @@ -42,12 +41,12 @@
#' [tm_iso()]\tab Create a layer of iso/contour lines \cr
#' [tm_rgb()]\tab Create a raster layer of an image \cr
#' }
#'
#'
#' Faceting (small multiples)
#' \tabular{ll}{
#' [tm_facets()]\tab Define facets \cr
#' }
#'
#'
#' Attributes:
#' \tabular{ll}{
#' [tm_grid()]\tab Create grid lines \cr
Expand All @@ -58,7 +57,7 @@
#' [tm_xlab()] and [tm_ylab()]\tab Create axis labels \cr
#' [tm_minimap()]\tab Create a minimap (view mode only) \cr
#' }
#'
#'
#' Layout element:
#' \tabular{ll}{
#' [tm_layout()]\tab Adjust the layout (main function)\cr
Expand All @@ -67,22 +66,22 @@
#' [tm_style()]\tab Apply a predefined style \cr
#' [tm_format()]\tab Apply a predefined format \cr
#' }
#'
#'
#' Change options:
#' \tabular{ll}{
#' [tmap_mode()]\tab Set the tmap mode: `"plot"` or `"view"`\cr
#' [ttm()]\tab Toggle between the modes \cr
#' [tmap_options()]\tab Set global tmap options (from [tm_layout()], [tm_view()], and a couple of others) \cr
#' [tmap_style()]\tab Set the default style \cr
#' }
#'
#'
#' Create icons:
#' \tabular{ll}{
#' [tmap_icons()]\tab Specify icons for markers or proportional symbols \cr
#' }
#'
#'
#' @section Output functions:
#'
#'
#' @section Output functions:
#' \tabular{ll}{
#' [print()]\tab Plot in graphics device or view interactively in web browser or RStudio's viewer pane \cr
#' [tmap_last()]\tab Redraw the last map \cr
Expand All @@ -91,8 +90,8 @@
#' [tmap_arrange()]\tab Create small multiples of separate maps \cr
#' [tmap_save()]\tab Save thematic maps (either as image or HTML file) \cr
#' }
#'
#' @section Spatial datasets:
#'
#' @section Spatial datasets:
#' \tabular{ll}{
#' [`World`]\tab World country data ([`sf`][`sf::sf`] object of polygons) \cr
#' [`NLD_prov`]\tab Netherlands province data ([`sf`][`sf::sf`] object of polygons) \cr
Expand All @@ -101,13 +100,12 @@
#' [`rivers`]\tab Rivers ([`sf`][`sf::sf`] object of lines) \cr
#' [`land`]\tab Global land cover ([`stars`][stars::st_as_stars()] object)\cr
#' }
#'
#'
#' @author Martijn Tennekes \email{mtennekes@@gmail.com}
#' @concept GIS
#' @concept thematic maps
#' @concept statistical maps
#' @concept choropleth
#' @concept bubble map
#' @seealso `vignette("tmap_sneak_peek")`, <https://r-tmap.github.io/tmap/>
#' @references Tennekes, M., 2018, {tmap}: Thematic Maps in {R}, Journal of Statistical Software, 84(6), 1-39, \doi{10.18637/jss.v084.i06}
"_PACKAGE"
1 change: 0 additions & 1 deletion R/qtm.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
#' called without prefix.
#' @return A [`tmap-element`]
#' @example ./examples/qtm.R
#' @seealso `vignette("tmap_sneak_peek")`
#' @references Tennekes, M., 2018, {tmap}: Thematic Maps in {R},
#' Journal of Statistical Software, 84(6), 1-39, \doi{10.18637/jss.v084.i06}
#' @export
Expand Down
65 changes: 32 additions & 33 deletions R/tmap_mode.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Set tmap mode to static plotting or interactive viewing
#'
#'
#' Set tmap mode to static plotting or interactive viewing.
#' The global option `tmap.mode` determines the whether thematic maps are plot
#' in the graphics device, or shown as an interactive leaflet map (see also [tmap_options()].
Expand All @@ -9,25 +9,25 @@
#' toggle thematic map and print last map: it does the same as `ttm()` followed
#' by [tmap_last()]; in order words, it shows the last map in the other mode.
#' It is recommended to use `tmap_mode()` in scripts and `ttm()`/`ttmp()` in the console.
#'
#'
#' # mode = "plot"
#'
#'
#' Thematic maps are shown in the graphics device.
#' This is the default mode, and supports all tmap's features,
#' such as small multiples (see [tm_facets()]) and extensive layout settings (see [tm_layout()]).
#' It is recommended to use [tmap_save()] for saving static maps.
#'
#'
#' # mode = "view"
#'
#'
#' Thematic maps are viewed interactively in the web browser or RStudio's Viewer pane.
#' Maps are fully interactive with tiles from OpenStreetMap or other map providers
#' (see [tm_tiles()]). See also [tm_view()] for options related to the `"view"` mode.
#' This mode generates a [leaflet::leaflet()] widget, which can also be directly
#' obtained with [tmap_leaflet()].
#' With R Markdown, it is possible to publish it to an HTML page.
#'
#' With R Markdown, it is possible to publish it to an HTML page.
#'
#' However, there are a couple of constraints in comparison to `"plot"`:
#'
#'
#' * The map is always projected according to the Web Mercator projection.
#' Although this projection is the de facto standard for interactive web-based mapping,
#' it lacks the equal-area property, which is important for many thematic maps,
Expand All @@ -37,12 +37,11 @@
#' * Text labels are not supported (yet)
#' * The layout options set with [tm_layout()]) regarding map format are not used.
#' However, the styling options still apply.
#'
#' @param mode One of `"plot"` or `"view"`. See Details for more info.
#'
#' @param mode One of `"plot"` or `"view"`. See Details for more info.
#' @return The previous tmap mode before switching.
#' @example ./examples/tmap_mode.R
#' @seealso
#' * `vignette("tmap_sneak_peek")`
#' @seealso
#' * [tmap_last()] to show the last map
#' * [tm_view()] for viewing options
#' * [tmap_leaflet()] for obtaining a leaflet widget
Expand All @@ -52,10 +51,10 @@
#' @export
tmap_mode = function(mode = NULL) {
current.mode = getOption("tmap.mode")

tOpt = get("tmapOptions", envir = .TMAP)
show.messages = tOpt$show.messages

modes = get_modes()

if (is.null(mode)) {
Expand All @@ -69,13 +68,13 @@ tmap_mode = function(mode = NULL) {
if (show.messages) cli::cli_inform(c(i = "tmap mode set to {.val {mode}}."))
}
invisible(current.mode)
}
}

# tmap_graphics = function(mode = NULL) {
# if (is.null(mode)) mode = getOption("tmap.mode")
# get("tmapOptions", envir = .TMAP)$graphics[[mode]]
# }
#
#
# tmap_graphics_name = function(mode = NULL) {
# tmap_graphics(mode = mode)$name
# }
Expand All @@ -85,13 +84,13 @@ get_modes = function() {
}

#' Set the design mode
#'
#'
#' When the so-called "design mode" is enabled, inner and outer margins,
#' legend position, and aspect ratio are shown explicitly in plot mode.
#' Also, information about aspect ratios is printed in the console.
#' This function sets the global option `tmap.design.mode`.
#' It can be used as toggle function without arguments.
#'
#'
#' @seealso [tmap_options()]
#' @param design.mode Logical value that determines the design mode.
#' If omitted then the design mode is toggled.
Expand All @@ -103,18 +102,18 @@ tmap_design_mode = function(design.mode) {
if (!is.logical(design.mode)) stop("design.mode is not a logical")
design.mode[1]
}

options(tmap.design.mode = dm)
message(
"design.mode: ", if (!dm) "OFF" else "ON",
if (dm && getOption("tmap.mode") == "view") " (only effective in plot mode)" else "")
}

#' Set the development mode
#'
#'
#' When the so-called "development mode" is enabled, helpful messages and timings
#' are printed in the console
#'
#'
#' @param devel.mode logical value that determines the development mode.
#' If omitted then the development mode is toggled.
#' @export
Expand All @@ -125,7 +124,7 @@ tmap_devel_mode = function(devel.mode) {
if (!is.logical(devel.mode)) stop("devel.mode is not a logical")
devel.mode[1]
}

options(tmap.devel.mode = dm)
message("devel.mode: ", if (!dm) "OFF" else "ON")
}
Expand All @@ -137,48 +136,48 @@ pm = function(message) {

po = function(...) {
e = substitute(list(...))
nms = sapply(e, deparse)[-1]
nms = sapply(e, deparse)[-1]

x = list(...)

for (i in seq_along(x)) {
cat("<==================== ", nms[i], "===============>\n")
print(x[[i]])
if (i == length(x)) {
cat("</============================================>\n")
}
}

invisible()
}

so = function(...) {
e = substitute(list(...))
nms = sapply(e, deparse)[-1]
nms = sapply(e, deparse)[-1]

x = list(...)

for (i in seq_along(x)) {
cat("<==================== ", nms[i], "===============>\n")
str(x[[i]])
if (i == length(x)) {
cat("</============================================>\n")
}
}

invisible()
}

#' @rdname tmap_mode
#' @export
ttm = function() {
current.mode = getOption("tmap.mode")

modes = get_modes()

id = match(current.mode, modes) + 1L
if (id > length(modes)) id = 1L

tmap_mode(modes[id])
invisible(current.mode)
}
Expand Down
3 changes: 0 additions & 3 deletions man/qtm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/tmap-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/tmap_mode.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f9dc4bb

Please sign in to comment.