Skip to content

Commit 54273ab

Browse files
closes #1182
1 parent 2396672 commit 54273ab

12 files changed

+624
-101
lines changed

R/api_check.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -2334,9 +2334,12 @@
23342334
#' @keywords internal
23352335
#' @noRd
23362336
.check_palette <- function(palette) {
2337+
# verifies if cols4all package is installed
2338+
.check_require_packages("cols4all")
23372339
# set caller to show in errors
23382340
.check_set_caller(".check_palette")
2339-
.check_that(palette %in% rownames(RColorBrewer::brewer.pal.info))
2341+
c4a_palette <- cols4all::c4a_info(palette, no.match = "null")
2342+
.check_that(.has(c4a_palette))
23402343
return(invisible(palette))
23412344
}
23422345
#' @title Checks sahpefile attribute

R/api_plot_raster.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
#' @keywords internal
352352
#' @noRd
353353
#' @param tile Probs cube to be plotted.
354-
#' @param label_plot Label to be plotted
354+
#' @param labels_plot Labels to be plotted
355355
#' @param palette A sequential RColorBrewer palette
356356
#' @param rev Reverse the color palette?
357357
#' @param scale Global scale for plot
@@ -360,7 +360,7 @@
360360
#' @return A plot object
361361
#'
362362
.plot_probs <- function(tile,
363-
label_plot,
363+
labels_plot,
364364
palette,
365365
rev,
366366
scale,
@@ -377,8 +377,13 @@
377377
# get all labels to be plotted
378378
labels <- .tile_labels(tile)
379379
names(labels) <- seq_len(length(labels))
380-
# check the label to be plotted
381-
.check_that(label_plot %in% labels)
380+
# check the labels to be plotted
381+
# if NULL, use all labels
382+
if (.has_not(labels_plot)) {
383+
labels_plot <- labels
384+
} else {
385+
.check_that(all(labels_plot %in% labels))
386+
}
382387
# size of data to be read
383388
max_size <- .conf("plot", "max_size")
384389
sizes <- .tile_overview_size(tile = tile, max_cog_size)
@@ -406,7 +411,7 @@
406411
p <- .tmap_probs_map(
407412
probs_st = probs_st,
408413
labels = labels,
409-
label_plot = label_plot,
414+
labels_plot = labels_plot,
410415
palette = palette,
411416
rev = rev,
412417
scale = scale,

R/api_plot_vector.R

+23-8
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@
5757
#' @keywords internal
5858
#' @noRd
5959
#' @param tile Tile to be plotted.
60-
#' @param label_plot Label to be plotted
60+
#' @param labels_plot Labels to be plotted
6161
#' @param palette A sequential RColorBrewer palette
6262
#' @param rev Revert the color of the palette?
6363
#' @param scale Global map scale
64-
#' @param tmap_params Tmap parameters
64+
#' @param tmap_params tmap parameters
6565
#'
6666
#' @return A plot object
6767
#'
6868
.plot_probs_vector <- function(tile,
69-
label_plot,
69+
labels_plot,
7070
palette,
7171
rev,
7272
scale,
@@ -83,8 +83,12 @@
8383
labels <- .tile_labels(tile)
8484
names(labels) <- seq_len(length(labels))
8585
# check the labels to be plotted
86-
.check_that(label_plot %in% labels)
87-
86+
# if NULL, use all labels
87+
if (.has_not(labels_plot)) {
88+
labels_plot <- labels
89+
} else {
90+
.check_that(all(labels_plot %in% labels))
91+
}
8892
# get the segments to be plotted
8993
sf_seg <- .segments_read_vec(tile)
9094

@@ -94,7 +98,7 @@
9498
palette = palette,
9599
rev = rev,
96100
labels = labels,
97-
label_plot = label_plot,
101+
labels_plot = labels_plot,
98102
scale = scale,
99103
tmap_params = tmap_params
100104
)
@@ -110,22 +114,33 @@
110114
#' @param palette A sequential RColorBrewer palette
111115
#' @param rev Revert the color of the palette?
112116
#' @param scale Global map scale
117+
#' @param tmap_params tmap parameters
113118
#'
114119
#' @return A plot object
115120
#'
116121
.plot_uncertainty_vector <- function(tile,
117122
palette,
118123
rev,
119-
scale) {
124+
scale,
125+
tmap_params) {
120126
# verifies if stars package is installed
121127
.check_require_packages("stars")
122128
# verifies if tmap package is installed
123129
.check_require_packages("tmap")
124130
# precondition - check color palette
125131
.check_palette(palette)
126-
# get the segements to be plotted
132+
# get the segments to be plotted
127133
sf_seg <- .segments_read_vec(tile)
128134
# obtain the uncertainty type
129135
uncert_type <- .vi(tile)[["band"]]
130136

137+
p <- .tmap_vector_uncert(
138+
sf_seg = sf_seg,
139+
palette = palette,
140+
rev = rev,
141+
type = uncert_type,
142+
scale = scale,
143+
tmap_params = tmap_params
144+
)
145+
return(p)
131146
}

R/api_tmap.R

+18-15
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@
188188
#' @noRd
189189
#' @param st Stars object.
190190
#' @param labels Class labels
191-
#' @param label_plot Class labels to be plotted
191+
#' @param labels_plot Class labels to be plotted
192192
#' @param palette A sequential RColorBrewer palette
193193
#' @param rev Reverse the color palette?
194194
#' @param scale Scale to plot map (0.4 to 1.0)
195195
#' @param tmap_params List with tmap params for detailed plot control
196196
#' @return A plot object
197197
.tmap_probs_map <- function(probs_st,
198198
labels,
199-
label_plot,
199+
labels_plot,
200200
palette,
201201
rev,
202202
scale,
@@ -212,7 +212,7 @@
212212
#'
213213
.tmap_probs_map.tmap_v3 <- function(probs_st,
214214
labels,
215-
label_plot,
215+
labels_plot,
216216
palette,
217217
rev,
218218
scale,
@@ -222,15 +222,16 @@
222222
palette <- paste0("-", palette)
223223
}
224224
# select stars bands to be plotted
225-
bds <- as.numeric(names(labels[labels %in% label_plot]))
225+
bds <- as.numeric(names(labels[labels %in% labels_plot]))
226226

227227
p <- tmap::tm_shape(probs_st[, , , bds]) +
228228
tmap::tm_raster(
229229
style = "cont",
230230
palette = palette,
231231
midpoint = NA,
232-
title = labels[labels %in% label_plot]
232+
title = labels[labels %in% labels_plot]
233233
) +
234+
tmap::tm_facets(sync = FALSE) +
234235
tmap::tm_graticules(
235236
labels.size = tmap_params[["graticules_labels_size"]]
236237
) +
@@ -258,12 +259,12 @@
258259
#' @param palette A sequential RColorBrewer palette
259260
#' @param rev Reverse the color palette?
260261
#' @param labels Class labels
261-
#' @param label_plot Class label to be plotted
262+
#' @param labels_plot Class labels to be plotted
262263
#' @param scale Scale to plot map (0.4 to 1.0)
263264
#' @param tmap_params Tmap parameters
264265
#' @return A plot object
265266
.tmap_vector_probs <- function(sf_seg, palette, rev,
266-
labels, label_plot,
267+
labels, labels_plot,
267268
scale, tmap_params){
268269
if (as.numeric_version(utils::packageVersion("tmap")) < "3.9")
269270
class(sf_seg) <- "tmap_v3"
@@ -273,7 +274,7 @@
273274
}
274275
#' @export
275276
.tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev,
276-
labels, label_plot,
277+
labels, labels_plot,
277278
scale, tmap_params){
278279
# revert the palette?
279280
if (rev) {
@@ -283,11 +284,11 @@
283284
# plot the segments
284285
p <- tmap::tm_shape(sf_seg) +
285286
tmap::tm_fill(
286-
label_plot,
287+
labels_plot,
287288
style = "cont",
288289
palette = palette,
289290
midpoint = NA,
290-
title = labels[labels %in% label_plot]) +
291+
title = labels[labels %in% labels_plot]) +
291292
tmap::tm_graticules(
292293
labels.size = tmap_params[["graticules_labels_size"]]
293294
) +
@@ -335,7 +336,8 @@
335336
palette = colors[["color"]]
336337
) +
337338
tmap::tm_graticules(
338-
labels.size = tmap_params[["graticules_labels_size"]]
339+
labels.size = tmap_params[["graticules_labels_size"]],
340+
ndiscr = 50
339341
) +
340342
tmap::tm_compass() +
341343
tmap::tm_layout(
@@ -426,11 +428,12 @@
426428
}
427429
# plot
428430
p <- tmap::tm_shape(sf_seg) +
429-
tmap::tm_polygons(type,
430-
palette = palette,
431-
style = "cont") +
431+
tmap::tm_fill(
432+
col = type,
433+
palette = palette
434+
) +
432435
tmap::tm_graticules(
433-
tmap_params[["graticules_labels_size"]]
436+
labels.size = tmap_params[["graticules_labels_size"]]
434437
) +
435438
tmap::tm_compass() +
436439
tmap::tm_layout(

0 commit comments

Comments
 (0)