Skip to content

Commit

Permalink
bumb cols4all 0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Oct 21, 2024
1 parent 3dd2801 commit 2315700
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 522 deletions.
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ Depends:
Imports:
classInt (>= 0.4-3),
cli,
colorblindcheck,
cols4all (>= 0.7-1),
cols4all (>= 0.8),
data.table,
grid,
htmltools,
Expand Down
30 changes: 0 additions & 30 deletions R/onLoad.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,6 @@
})
})) # needed for pretty ticks for continuous scale with trans enabled (like log scale)

if (packageVersion("cols4all") < "0.8") {
# NOTE: this is only needed until tmap4 is on CRAN, because cols4all 0.8 will be there sooner
cols4all = list(area7 = c("#FF9D9A", "#77AADD", "#F1CE63", "#2CA02C", "#B07AA1", "#9EDAE5", "#CC6677"),
area8 = c("#CC6677", "#AEC7E8", "#44BB99", "#B07AA1", "#BBCC33", "#FFAABB", "#B6992D", "#98DF8A"),
area9 = c("#EE8866", "#88CCEE", "#2CA02C", "#B07AA1", "#F1CE63", "#FFAABB", "#6699CC", "#44BB99", "#CC6677"),
area7d = c("#72190E", "#332288", "#225555", "#997700", "#437DBF", "#994F88", "#666633"),
area8d = c("#663333", "#1F77B4", "#225555", "#994F88", "#997700", "#332288", "#666633", "#661100"),
area9d = c("#72190E", "#1965B0", "#225555", "#994F88", "#997700", "#332288", "#666633", "#663333", "#437DBF"),
line7 = c("#1F77B4", "#2CA02C", "#E73F74", "#6699CC", "#994F88", "#117733", "#D37295"),
line8 = c("#DC050C", "#1F77B4", "#117733", "#994F88", "#999933", "#D37295", "#6699CC", "#E73F74"),
line9 = c("#EE3377", "#1F77B4", "#117733", "#CF1C90", "#999933", "#994455", "#6699CC", "#D37295", "#DC050C"),
friendly5 = c("#CC6677", "#F1CE63", "#117733", "#99DDFF", "#9467BD"),
friendly7 = c("#E65518", "#F2B701", "#009988", "#88CCEE", "#9467BD","#225522", "#882255"),
friendly9 = c("#E73F74", "#F1CE63", "#99DDFF", "#9467BD", "#009988", "#882255", "#225522", "#4B4B8F", "#999933"),
friendly11 = c("#E73F74", "#F1CE63", "#77AADD", "#9467BD", "#AAAA00", "#FF9D9A", "#99DDFF", "#B07AA1", "#225522", "#882255", "#4B4B8F"),
friendly13 = c("#E73F74", "#F1CE63", "#77AADD", "#009988", "#9467BD", "#FF9D9A", "#99DDFF", "#AAAA00", "#225522", "#882255", "#997700", "#4B4B8F", "#8C564B"))
cols4all::c4a_load(cols4all::c4a_data(cols4all, types = "cat", series = "cols4all"), overwrite = TRUE)

# due to disabled auto-reversing of palettes
hcl.blues3 = structure(c("#00366C", "#004D86", "#0066A5", "#037EC4", "#5295D4",
"#79ABE2", "#99BFEF", "#B6D3F9", "#D0E4FF", "#E6F1FF", "#F9F9F9"
), range_matrix = structure(c(0.5, 0.2, 0.2, 0.166666666666667,
0.133333333333333, 0.1, 0.0666666666666667, 0.0333333333333333,
0, 0, 0, 0.5, 0.8, 0.8, 0.833333333333333, 0.866666666666667,
0.9, 0.933333333333333, 0.966666666666667, 1, 1, 1), dim = c(11L, 2L)), space = "Lab")

cols4all::c4a_load(cols4all::c4a_data_as_is(list("blues3" = hcl.blues3), types = "seq", series = "hcl"), overwrite = TRUE)
}


}

#' @export
Expand Down
19 changes: 11 additions & 8 deletions R/tm_layers_cartogram.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' Map layer: cartogram
#'
#'
#' Map layer that draws a cartogram
#'
#'
#' @inheritParams tm_text
#' @inheritDotParams tm_polygons
#' @export
Expand All @@ -15,9 +15,9 @@ tm_cartogram = function(size = 1,
...) {
po = plot.order
#trans.args$type = match.arg(trans.args$type)

# types: "cont", "ncont", "dorling"

tmp = do.call(tm_polygons, c(list(...), list(options = options$polygons)))
tmp[[1]] = within(tmp[[1]], {
trans.fun = tmapTransCartogram
Expand Down Expand Up @@ -76,7 +76,8 @@ tm_cartogram_dorling = function(size = 1,
options = options), args))
}

#' @name opt_tm
#' @name opt_tm_cartogram
#' @rdname tm_cartogram
#' @param type cartogram type, one of: "cont" for contiguous cartogram, "ncont" for non-contiguous cartogram and "dorling" for Dorling cartograms
#' @param itermax, maximum number of iterations (see [cartogram::cartogram_cont()])
#' @param ... arguments passed on to [cartogram::cartogram_cont()]
Expand All @@ -89,22 +90,24 @@ opt_tm_cartogram = function(type = "cont",
polygons = do.call(opt_tm_polygons, list(...)))
}

#' @name opt_tm
#' @name opt_tm_cartogram_ncont
#' @rdname tm_cartogram
#' @param expansion factor expansion, see [cartogram::cartogram_ncont()] (argument `k`)
#' @param inplace should each polygon be modified in its original place? (`TRUE` by default)
#' @export
opt_tm_cartogram_ncont = function(type = "ncont",
expansion = 1,
inplace = FALSE,
...) {

list(cartogram = list(mapping.args = list(),
trans.args = list(type = type, expansion = expansion, inplace = inplace)),
polygons = do.call(opt_tm_polygons, list(...)))
}


#' @name opt_tm
#' @name opt_tm_cartogram_dorling
#' @rdname tm_cartogram
#' @param share share of the bounding box filled with the larger circle (see [cartogram::cartogram_dorling()] argument `k`)
#' @export
opt_tm_cartogram_dorling = function(type = "dorling",
Expand Down
90 changes: 45 additions & 45 deletions R/tm_layers_lines.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#' Map layer: lines
#'
#'
#' Map layer that draws lines. Supported visual variables are: `col` (the color), `lwd` (line width), `lty` (line type), and `col_alpha` (color alpha transparency).
#'
#'
#' The visual variable arguments (e.g. `col`) can be specified with either a data
#' variable name (e.g., a spatial vector attribute or a raster layer of the object
#' specified in [tm_shape()]), or with a visual value (for `col`, a color is expected).
#' Multiple values can be specified: in that case facets are created.
#' These facets can be combined with other faceting data variables, specified with [tm_facets()].
#'
#'
#' * The `*.scale` arguments determine the used scale to map the data values to
#' visual variable values. These can be specified with one of the available
#' `tm_scale_*()` functions. The default is specified by the tmap option ([tm_options()]) `scales.var`.
#'
#'
#' * The `*.legend` arguments determine the used legend, specified with [tm_legend()].
#' The default legend and its settings are determined by the tmap options ([tm_options()]) `legend.` .
#'
#'
#' * The `*.chart` arguments specify additional charts, specified with `tm_chart_`, e.g. [tm_chart_histogram()]
#'
#'
#' * The `*.free` arguments determine whether scales are applied freely across facets, or shared.
#' A logical value is required. They can also be specified with a vector of three
#' logical values; these determine whether scales are applied freely per facet dimension.
Expand All @@ -27,17 +27,17 @@
#' scale, and therefore its own legend. For facet wraps and stacks
#' ([tm_facets_wrap()] and [tm_facets_stack()]) there is only one facet dimension,
#' so the `*.free` argument requires only one logical value.
#'
#'
#' @param col,col.scale,col.legend,col.chart,col.free Visual variable that determines the col color. See details.
#' @param lwd,lwd.scale,lwd.legend,lwd.chart,lwd.free Visual variable that determines the line width. See details.
#' @param lty,lty.scale,lty.legend,lty.chart,lty.free Visual variable that determines the line type. See details.
#' @param col_alpha,col_alpha.scale,col_alpha.legend,col_alpha.chart,col_alpha.free Visual variable that determines the border color alpha transparency. See details.
#' @param linejoin,lineend line join and line end. See [gpar()][grid::gpar()] for details.
#' @param plot.order Specification in which order the spatial features are drawn. See [tm_plot_order()] for details.
#' @param options options passed on to the corresponding `opt_<layer_function>` function
#' @param options options passed on to the corresponding `opt_<layer_function>` function
#' @inheritParams tm_polygons
#' @param ... to catch deprecated arguments from version < 4.0
#' @example ./examples/tm_lines.R
#' @example ./examples/tm_lines.R
#' @export
tm_lines = function(col = tm_const(),
col.scale = tm_scale(),
Expand Down Expand Up @@ -71,17 +71,17 @@ tm_lines = function(col = tm_const(),
id = "",
options = opt_tm_lines(),
...) {

args = list(...)
args_called = as.list(match.call()[-1]) #lapply(as.list(match.call()[-1]), eval, envir = parent.frame())

if (any(v3_only("tm_lines") %in% names(args))) {
layer_fun = if ("called_from" %in% names(args)) {
args$called_from
} else {
"lines"
}

v3_start_message()
if (!("style" %in% names(args))) {
if (!"breaks" %in% names(args)) {
Expand All @@ -92,16 +92,16 @@ tm_lines = function(col = tm_const(),
} else {
style = args$style
}

v3_list_init()
if (length(style) > 1) {
style = style[1]
.TMAP$v3_list$mult = TRUE
}
# v3 visual variable: col
col.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
col.scale.args = c(list(n = v3_impute(args, "n", 5),
style = style,
style.args = v3_impute(args, "style.args", list())),
if (style %in% c("cont", "log10")) {
c({
if (!is.null(args$breaks)) {
Expand All @@ -116,24 +116,24 @@ tm_lines = function(col = tm_const(),
},
list(outliers.trunc = c(TRUE, FALSE)))
} else {
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
list(breaks = v3_impute(args, "breaks", NULL),
interval.closure = v3_impute(args, "interval.closure", "left"),
drop.levels = v3_impute(args, "drop.levels", FALSE))
},
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
list(midpoint = v3_impute(args, "midpoint", NULL),
as.count = v3_impute(args, "as.count", NA),
values = v3_impute(args, "palette", NA, "values"),
values.repeat = !v3_impute(args, "stretch.palette", TRUE, "values.repeat"),
values.range = v3_impute(args, "contrast", NA, "values.range"),
values.scale = 1,
value.na = v3_impute(args, "colorNA", NA, "value.na"),
value.null = v3_impute(args, "colorNULL", NA, "value.null"),
value.neutral = NA,
labels = v3_impute(args, "labels", NULL),
label.na = v3_impute(args, "textNA", "Missing", "label.na"),
label.null = NA,
label.format = v3_impute(args, "legend.format", list(), "label.format")))

col.scale.args$fun_pref = if (style == "cat") {
"categorical"
} else if (style %in% c("fixed", "sd", "equal", "pretty", "quantile",
Expand All @@ -157,17 +157,17 @@ tm_lines = function(col = tm_const(),
}
}

col.scale = do.call("tm_scale", args = col.scale.args)
col.scale = do.call("tm_scale", args = col.scale.args)



if ("alpha" %in% names(args)) {
col_alpha = args$alpha
v3_message_col_alpha(layer_fun = layer_fun, orig = "alpha")

}


v3_list_init()
if ("legend.col.show" %in% names(args) && !args$legend.col.show) {
v3_tm_legend_hide(layer_fun, arg = "legend.col.show", vv = "col")
Expand All @@ -181,7 +181,7 @@ tm_lines = function(col = tm_const(),
col.legend = do.call("tm_legend", col.legend.args)
v3_tm_legend(fun = layer_fun, vv = "col", arg_list = v3_list_get())
}

# v3 visual variable: lwd
# v3 visual variable: size
v3_list_init()
Expand All @@ -190,8 +190,8 @@ tm_lines = function(col = tm_const(),
values.scale = v3_impute(args, "scale", 1, "values.scale"),
fun_pref = "continuous")
if ("lwd" %in% names(args_called)) v3_tm_scale(scale_fun = "continuous", vv = "lwd", layer_fun = layer_fun, arg_list = v3_list_get())
lwd.scale = do.call("tm_scale", args = lwd.scale.args)
lwd.scale = do.call("tm_scale", args = lwd.scale.args)

v3_list_init()
if ("legend.lwd.show" %in% names(args) && !args$legend.lwd.show) {
v3_tm_legend_hide(layer_fun, arg = "legend.lwd.show", vv = "lwd")
Expand All @@ -205,17 +205,17 @@ tm_lines = function(col = tm_const(),
if ("lwd" %in% names(args_called)) v3_tm_legend(fun = layer_fun, vv = "lwd", arg_list = v3_list_get())
lwd.legend = do.call("tm_legend", lwd.legend.args)
}


if ("legend.hist" %in% names(args) && args$legend.hist) {
col.chart = tm_chart_histogram()
v3_tm_chart_hist(layer_fun = layer_fun, vv = "col", arg = "legend.hist")

# to do: histogram title
}
}



tm_element_list(tm_element(
layer = "lines",
Expand Down Expand Up @@ -247,7 +247,7 @@ tm_lines = function(col = tm_const(),
legend = col_alpha.legend,
chart = col_alpha.chart,
free = col_alpha.free)),

gpar = tmapGpar(fill = NA,
col = "__col",
shape = NA,
Expand All @@ -273,7 +273,7 @@ tm_lines = function(col = tm_const(),
subclass = c("tm_aes_layer", "tm_layer")))
}

#' @rdname opt_tm
#' @rdname tm_lines
#' @param lines.only should only line geometries of the shape object (defined in [tm_shape()]) be plotted, or also other geometry types (like polygons)? By default `"ifany"`, which means `TRUE` in case a geometry collection is specified.
#' @export
opt_tm_lines = function(lines.only = "ifany") {
Expand Down
Loading

0 comments on commit 2315700

Please sign in to comment.