Skip to content

Commit

Permalink
Merge pull request #786 from olivroy/line-length
Browse files Browse the repository at this point in the history
Line length
  • Loading branch information
mtennekes committed Sep 21, 2023
2 parents 86a608c + f9fd4e6 commit c78278f
Show file tree
Hide file tree
Showing 72 changed files with 1,824 additions and 592 deletions.
16 changes: 11 additions & 5 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#' World and Netherlands map
#'
#' Maps of the world and the Netherlands (province and municipality level), class [`sf`][`sf::sf`]
#' Maps of the world and the Netherlands (province and municipality level),
#' class [`sf`][`sf::sf`]
#'
#' The default projections for these maps are Eckhart IV (World) and Rijksdriehoekstelsel (Netherlands). See below. The projection can be changed temporarily for plotting purposes by using the projection argument of [tm_shape()].
#' The default projections for these maps are Eckhart IV (World) and
#' Rijksdriehoekstelsel (Netherlands). See below. The projection can be changed
#' temporarily for plotting purposes by using the projection argument of [tm_shape()].
#'
#' `World` World map. The default projection for this world map is Eckhart IV since area sizes are preserved, which is a very important property for choropleths.
#' `World` World map. The default projection for this world map is Eckhart IV
#' since area sizes are preserved, which is a very important property for choropleths.
#'
#' `NLD_prov` and `NLD_muni`, maps of the Netherlands at province and municipality level of 2013. The used projection is the Rijksdriehoekstelsel projection.
#' `NLD_prov` and `NLD_muni`, maps of the Netherlands at province and municipality
#' level of 2013. The used projection is the Rijksdriehoekstelsel projection.
#'
#' **Important:** publication of these maps is only allowed when citing Statistics Netherlands (CBS) and Kadaster Nederland as source.
#' **Important:** publication of these maps is only allowed when citing
#' Statistics Netherlands (CBS) and Kadaster Nederland as source.
#'
#' @rdname Shapes
#' @format NULL
Expand Down
8 changes: 6 additions & 2 deletions R/pkg.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#' Thematic Map Visualization
#'
#' Thematic maps are geographical maps in which spatial data distributions are visualized. 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.
#' Thematic maps are geographical maps in which spatial data distributions are visualized.
#' 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.
#' 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 Down
72 changes: 53 additions & 19 deletions R/qtm.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,69 @@
#' Quick thematic map plot
#'
#' Draw a thematic map quickly. This function is a convenient wrapper of the main plotting method of stacking [`tmap-element`]s. Without arguments or with a search term, this functions draws an interactive map.
#' Draw a thematic map quickly. This function is a convenient wrapper of the main
#' plotting method of stacking [`tmap-element`]s. Without arguments or with a
#' search term, this functions draws an interactive map.
#'
#' The first argument is a shape object (normally specified by [tm_shape()]). The next arguments, from `fill` to `raster`, are the aesthetics from the main layers. The remaining arguments are related to the map layout. Any argument from any main layer function, such as [tm_polygons()], can be specified (see `...`). It is also possible to stack [`tmap-element`]s on a `qtm` plot. See examples.
#' The first argument is a shape object (normally specified by [tm_shape()]).
#' The next arguments, from `fill` to `raster`, are the aesthetics from the main
#' layers. The remaining arguments are related to the map layout. Any argument
#' from any main layer function, such as [tm_polygons()], can be specified (see `...`).
#' It is also possible to stack [`tmap-element`]s on a `qtm` plot. See examples.
#'
#' By default, a scale bar is shown. This option can be set with [tmap_options()] (argument `qtm.scalebar`). A minimap is shown by default when `qtm` is called without arguments of with a search term. This option can be set with [tmap_options()] (argument `qtm.minimap`).
#' By default, a scale bar is shown. This option can be set with [tmap_options()]
#' (argument `qtm.scalebar`). A minimap is shown by default when `qtm` is called
#' without arguments of with a search term. This option can be set with [tmap_options()]
#' (argument `qtm.minimap`).
#'
#' @param shp One of
#' \itemize{
#' \item shape object, which is an object from a class defined by the [`sf`][`sf::sf`] or [`stars`][stars::st_as_stars()] package. Objects from the packages `sp` and `raster` are also supported, but discouraged.
#' \item Not specified, i.e. `qtm()` is executed. In this case a plain interactive map is shown.
#' \item An OpenStreetMap search string, e.g. `qtm("Amsterdam")`. In this case a plain interactive map is shown positioned according to the results of the search query (from OpenStreetMap nominatim)
#' }
#' @param shp One of:
#' * shape object, which is an object from a class defined by the [`sf`][`sf::sf`]
#' or [`stars`][stars::st_as_stars()] package. Objects from the packages `sp`
#' and `raster` are also supported, but discouraged.
#' * Not specified, i.e. `qtm()` is executed. In this case a plain interactive
#' map is shown.
#' * An OpenStreetMap search string, e.g. `qtm("Amsterdam")`. In this case a
#' plain interactive map is shown positioned according to the results of the
#' search query (from OpenStreetMap nominatim)
#' @param fill,col,size,shape,lwd,lty,fill_alpha,col_alpha Visual variables.
#' @param by data variable name by which the data is split, or a vector of two variable names to split the data by two variables (where the first is used for the rows and the second for the columns). See also [tm_facets()]
#' @param scale numeric value that serves as the global scale parameter. All font sizes, symbol sizes, border widths, and line widths are controlled by this value. The parameters `symbols.size`, `text.size`, and `lines.lwd` can be scaled separately with respectively `symbols.scale`, `text.scale`, and `lines.scale`. See also `...`.
#' @param title main title. For legend titles, use `X.style`, where X is the layer name (see `...`).
#' @param crs Either a [`crs`][sf::st_crs()] object or a character value (`PROJ.4` character string). By default, the projection is used that is defined in the `shp` object itself.
#' @param by data variable name by which the data is split, or a vector of two
#' variable names to split the data by two variables (where the first is used
#' for the rows and the second for the columns). See also [tm_facets()].
#' @param scale numeric value that serves as the global scale parameter. All font
#' sizes, symbol sizes, border widths, and line widths are controlled by this value.
#' The parameters `symbols.size`, `text.size`, and `lines.lwd` can be scaled
#' separately with respectively `symbols.scale`, `text.scale`, and
#' `lines.scale`. See also `...`.
#' @param title main title. For legend titles, use `X.style`, where X is the
#' layer name (see `...`).
#' @param crs Either a [`crs`][sf::st_crs()] object or a character value
#' (`PROJ.4` character string). By default, the projection is used that is
#' defined in the `shp` object itself.
#' @param bbox bounding box. Argument passed on to [tm_shape()]
#' @param basemaps name(s) of the provider or an URL of a tiled basemap. It is a shortcut to [tm_basemap()]. Set to `NULL` to disable basemaps. By default, it is set to the tmap option `basemaps`.
#' @param overlays name(s) of the provider or an URL of a tiled overlay map. It is a shortcut to [tm_tiles()].
#' @param basemaps name(s) of the provider or an URL of a tiled basemap.
#' It is a shortcut to [tm_basemap()]. Set to `NULL` to disable basemaps.
#' By default, it is set to the tmap option `basemaps`.
#' @param overlays name(s) of the provider or an URL of a tiled overlay map.
#' It is a shortcut to [tm_tiles()].
#' @param zindex zindex
#' @param group group
#' @param group.control group.control
#' @param style Layout options (see [tm_layout()]) that define the style. See [tmap_style()] for details.
#' @param format Layout options (see [tm_layout()]) that define the format. See [tmap_format()] for details.
#' @param ... arguments passed on to the `tm_*` functions. The prefix of these arguments should be with the layer function name without `"tm_"` and a period. For instance, the palette for polygon fill color is called `fill.palette`. The following prefixes are supported: `shape.`, `fill.`, `borders.`, `polygons.`, `symbols.`, `dots.`, `lines.`, `raster.`, `text.`, `layout.`, `grid.`, `facets.`, and `view.`. Arguments that have a unique name, i.e. that does not exist in any other layer function, e.g. `convert2density`, can also be called without prefix.
#' @param style Layout options (see [tm_layout()]) that define the style.
#' See [tmap_style()] for details.
#' @param format Layout options (see [tm_layout()]) that define the format.
#' See [tmap_format()] for details.
#' @param ... arguments passed on to the `tm_*` functions. The prefix of these
#' arguments should be with the layer function name without `"tm_"` and a period.
#' For instance, the palette for polygon fill color is called `fill.palette`.
#' The following prefixes are supported: `shape.`, `fill.`, `borders.`, `polygons.`,
#' `symbols.`, `dots.`, `lines.`, `raster.`, `text.`, `layout.`, `grid.`,
#' `facets.`, and `view.`. Arguments that have a unique name, i.e. that does
#' not exist in any other layer function, e.g. `convert2density`, can also be
#' 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}
#' @references Tennekes, M., 2018, {tmap}: Thematic Maps in {R},
#' Journal of Statistical Software, 84(6), 1-39, \doi{10.18637/jss.v084.i06}
#' @export
qtm <- function(shp,
fill = tm_const(),
Expand Down
3 changes: 2 additions & 1 deletion R/theme_ps.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#' ggplot2 theme for proportional symbols
#'
#' ggplot2 theme for proportional symbols. By default, this theme only shows the plotting area, so without titles, axes, and legend
#' ggplot2 theme for proportional symbols. By default, this theme only shows the
#' plotting area, so without titles, axes, and legend.
#'
#' @param base_size base size
#' @param base_family base family
Expand Down
21 changes: 16 additions & 5 deletions R/tm_add_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
#'
#' Map component that adds a manual legend
#'
#' @param ... visual variables and arguments passed on to `tm_legend`. By default, the argument `type` is set to `"Symbols"`, which means that the supported visual variables are: `"fill"`, `"col"`, `"shape"`, `"size"`, `"fill_alpha"`, `"col_alpha"`, `"lty"`, `"lwd"`, `"linejoin"`, and `"lineend"`.
#' @param ... visual variables and arguments passed on to `tm_legend()`.
#' By default, the argument `type` is set to `"Symbols"`, which means that the
#' supported visual variables are: `"fill"`, `"col"`, `"shape"`, `"size"`,
#' `"fill_alpha"`, `"col_alpha"`, `"lty"`, `"lwd"`, `"linejoin"`, and `"lineend"`.
#' @param labels labels
#' @param type the layer type from which the visual variables (see ...) are taken. Options: `"Symbols"` (default), `"Lines"`, `"Polygons"`, and `"Text"`.
#' @param type the layer type from which the visual variables (see `...`) are taken.
#' Options: `"Symbols"` (default), `"Lines"`, `"Polygons"`, and `"Text"`.
#' @param title text of the title
#' @param design legend design
#' @param orientation legend orientation
#' @param group Name of the group to which this layer belongs. This is only relevant in view mode, where layer groups can be switched (see `group.control`)
#' @param group.control In view mode, the group control determines how layer groups can be switched on and off. Options: `"radio"` for radio buttons (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 group Name of the group to which this layer belongs. This is only
#' relevant in view mode, where layer groups can be switched (see `group.control`)
#' @param group.control In view mode, the group control determines how
#' layer groups can be switched on and off. Options: `"radio"` for radio
#' buttons (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 resize.as.group resize.as.group
#' @param z z
#' @export
Expand All @@ -35,7 +44,9 @@ tmapAddedLegend = function(comp, o) {
l = update_l(o = o, l = comp, v = "", mfun = comp$type)

fun = paste0("tm_", tolower(comp$type))
if (!exists(fun)) stop(paste0("type \"", comp$type, "\" not supported because tm_", comp$type, " not found"), call. = FALSE)
if (!exists(fun)) {
stop(paste0("type \"", comp$type, "\" not supported because tm_", comp$type, " not found"), call. = FALSE)
}
res = do.call(fun, args = list())
gp = res[[1]]$gpar

Expand Down
4 changes: 3 additions & 1 deletion R/tm_components.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ tm_compass <- function(north,

#' Map component: scale bar
#'
#' Map component that adds a scale bar. As of version 4.0, `tm_scalebar()` is used instead of `tm_scale_bar` (now deprecated), because of the potential confusion with the `tm_scale_x` scaling functions (like [tm_scale_continuous()]).
#' Map component that adds a scale bar. As of version 4.0, `tm_scalebar()` is
#' used instead of `tm_scale_bar()` (now deprecated), because of the potential
#' confusion with the `tm_scale_*()` scaling functions (like [tm_scale_continuous()]).
#'
#' @param breaks breaks
#' @param width width
Expand Down
8 changes: 6 additions & 2 deletions R/tm_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ tm_element_list_sel = function(tml, subclass) {

#' Retrieve the last map to be modified or created
#'
#' Retrieve the last map to be modified or created. Works in the same way as [ggplot2::last_plot()], although there is a difference: `tmap_last()` returns the last call instead of the stacked [`tmap-element`]s.
#' Retrieve the last map to be modified or created. Works in the same way
#' as [ggplot2::last_plot()], although there is a difference:
#' `tmap_last()` returns the last call instead of the stacked [`tmap-element`]s.
#'
#' @return call
#' @export
#' @seealso [tmap_save()]
tmap_last = function() {
.x = get("last_map", envir = .TMAP)
if (is.null(.x) && get("tmapOptions", envir = .TMAP)$show.warnings) warning("A map has not been created yet")
if (is.null(.x) && get("tmapOptions", envir = .TMAP)$show.warnings) {
warning("A map has not been created yet")
}
eval(.x)
}

Expand Down
Loading

0 comments on commit c78278f

Please sign in to comment.