Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Dec 5, 2024
1 parent 2653cc4 commit 6daae67
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion R/messages.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,6 @@ message_webgl_checks = function(checks, checkif) {

message_qtm_empty = function() {
cli::cli_inform(
"{.field [qtm]} nothing to show. Either specify {.arg shp} or {.arg basemap}."
"{.field [qtm]} nothing to show. Either specify {.arg shp} or {.arg basemap}. Alternatively, switch to view mode with {.code tmap_mode(\"view\")}"
)
}
22 changes: 12 additions & 10 deletions R/qtm.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
#' @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 format Deprecated, see [tm_format()] for alternatives
#' @param ... arguments associated with the visual variables are passed on
#' to the layer functions [tm_polygons()], [tm_lines()], [tm_symbols()],
#' and [tm_text()].
Expand Down Expand Up @@ -112,14 +111,14 @@ qtm = function(shp = NULL,
o = tmap_options_mode()
show.warnings = o$show.warnings

# if (missing(shp) || is.character(shp)) {
# viewargs = args[intersect(names(args), names(formals(tm_view)))]
# if (!missing(shp)) viewargs$bbox = shp
# g = c(tm_basemap(basemaps), tm_tiles(overlays), do.call("tm_view", viewargs))
# attr(g, "qtm_shortcut") = TRUE
# class(g) = "tmap"
# return(g)
# }
if (missing(shp) || is.character(shp)) {
viewargs = args[intersect(names(args), names(formals(tm_view)))]
if (!missing(shp)) viewargs$bbox = shp
g = c(tm_basemap(basemaps), tm_tiles(overlays), do.call("tm_view", viewargs))
attr(g, "qtm_shortcut") = TRUE
class(g) = "tmap"
return(g)
}


if (!missing(shp)) {
Expand Down Expand Up @@ -196,6 +195,9 @@ qtm = function(shp = NULL,
if ("tiles" %in% args_called || o$tiles.show) {
g = g + do.call(tm_tiles, list(server = args$overlays))
}
if ("style" %in% args_called) {
g = g + tm_style(args$style)
}

if (o$qtm.scalebar) g = g + tm_scalebar()
if (o$qtm.minimap) g = g + tm_minimap()
Expand Down
2 changes: 1 addition & 1 deletion R/tmapScale_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ get_scale_defaults = function(scale, o, aes, layer, cls, ct = NULL) {
if ((!is.na(ona) && "value.na" %in% scale$called) || is.null(m)) {
ona
} else{
cols4all::c4a_na(values)
getPalNA(as.character(values[1]))
}
} else {
value.na
Expand Down
15 changes: 13 additions & 2 deletions R/tmap_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,22 @@ tmap_options = function(..., crs, facet.max, facet.flip, free.scales, raster.max

#' @name tmap_options_mode
#' @param mode mode, e.g. `"plot"` or `"view"`
#' @param style style. If specified, the style specific options are returned
#' @param default.options return the default options or the current options?
#' @rdname tmap_options
#' @export
tmap_options_mode = function(mode = NA, default.options = FALSE) {
o = if (default.options) .defaultTmapOptions else get("tmapOptions", envir = .TMAP)
tmap_options_mode = function(mode = NA, style = NULL, default.options = FALSE) {
if (default.options) {
o = .defaultTmapOptions
} else {
o = get("tmapOptions", envir = .TMAP)

if (!is.null(style)) {
check_style(style)
s = get("tmapStyles", envir = .TMAP)[[style]]
o = complete_options(s, o)
}
}

if (is.na(mode)) mode = getOption("tmap.mode")
opt2 = o$modes[[mode]]
Expand Down
7 changes: 7 additions & 0 deletions R/tmap_palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ getPal = function(name, n = NA, rep = TRUE, range = NA, reversed = FALSE) {
cols4all::c4a(name, n = n, nm_invalid = {if (rep) "repeat" else "interpolate"}, range = range, reverse = reversed)
}

getPalNA = function(name) {
if (name %in% c("cat", "seq", "div")) {
name = cols4all::c4a_options("defaults")$defaults[[name]]
}
cols4all::c4a_na(name)
}

getPalBiv = function(name, m = NA, n = NA, rep = TRUE) {
cols4all::c4a(name, m = m, n = n, nm_invalid = {if (rep) "repeat" else "interpolate"})
}
Expand Down
27 changes: 4 additions & 23 deletions examples/qtm.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,11 @@ data(World, rivers, metro)
qtm(World)

# choropleth
qtm(World, fill = "economy", format = "World", style = "col_blind", projection = "+proj=eck4")
qtm(World, fill = "economy", style = "cobalt", crs = "+proj=eck4")

# choropleth with more specifications
qtm(World, fill="HPI", fill.n = 9, fill.palette = "div",
fill.title = "Happy Planet Index", fill.id = "name",
style = "gray", format = "World", projection = "+proj=eck4")
# this map can also be created with the main plotting method,
# which is recommended in this case.
\dontrun{
tm_shape(World, projection = "+proj=eck4") +
tm_polygons("HPI", n = 9, palette = "div",
title = "Happy Planet Index", id = "name") +
tm_style("gray") +
tm_format("World")
}

# bubble map
\dontrun{
qtm(World, borders = NULL) +
qtm(metro, symbols.size = "pop2010",
symbols.title.size= "Metropolitan Areas",
symbols.id= "name",
format = "World")
}
qtm(World, col = NULL) +
qtm(metro, size = "pop2010",
size.legend = tm_legend("Metropolitan Areas"))

# dot map
\dontrun{
Expand Down

0 comments on commit 6daae67

Please sign in to comment.