Skip to content

Commit

Permalink
Add label_size to "spcv_block" to make label size configurable (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s authored Aug 15, 2023
1 parent d8b5d12 commit 3e7eeb2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
10 changes: 9 additions & 1 deletion R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#' Whether to show an overlay of the spatial blocks polygons.
#' @param show_labels `[logical(1)]`\cr
#' Whether to show an overlay of the spatial block IDs.
#' @param label_size `[numeric(1)]`\cr
#' Label size of block labels. Only applies for `show_labels = TRUE`.
#' @param ... Passed to `geom_sf()`. Helpful for adjusting point sizes and
#' shapes.
#' @param sample_fold_n `[integer]`\cr
Expand Down Expand Up @@ -97,6 +99,7 @@ autoplot.ResamplingSpCVBlock = function( # nolint
show_blocks = FALSE,
show_labels = FALSE,
sample_fold_n = NULL,
label_size = 2,
...) {

autoplot_spatial(
Expand All @@ -109,6 +112,7 @@ autoplot.ResamplingSpCVBlock = function( # nolint
show_blocks = show_blocks,
show_labels = show_labels,
sample_fold_n = sample_fold_n,
label_size = label_size,
... = ...
)
}
Expand All @@ -126,6 +130,7 @@ autoplot.ResamplingRepeatedSpCVBlock = function( # nolint
show_blocks = FALSE,
show_labels = FALSE,
sample_fold_n = NULL,
label_size = label_size,
...) {

autoplot.ResamplingSpCVBlock(
Expand All @@ -138,6 +143,7 @@ autoplot.ResamplingRepeatedSpCVBlock = function( # nolint
show_blocks = show_blocks,
show_labels = show_labels,
sample_fold_n = sample_fold_n,
label_size = label_size,
... = ...,
# ellipsis
repeats_id = repeats_id
Expand Down Expand Up @@ -889,6 +895,7 @@ autoplot_spatial = function(
show_blocks = FALSE,
show_labels = FALSE,
sample_fold_n = NULL,
label_size = NULL,
...) {

mlr3misc::require_namespaces(c("sf", "patchwork", "ggtext"))
Expand Down Expand Up @@ -931,7 +938,8 @@ autoplot_spatial = function(
resampling_mod = coords_resamp,
sample_fold_n = sample_fold_n, fold_id = fold_id,
repeats_id = repeats_id, plot_as_grid = plot_as_grid,
show_blocks = show_blocks, show_labels = show_labels, ...)
show_blocks = show_blocks, show_labels = show_labels,
label_size = label_size, ...)
} else {
### One plot showing all test folds ----------------------------------------
plot = autoplot_all_folds_dt(task = task, resampling = coords_resamp,
Expand Down
5 changes: 2 additions & 3 deletions R/autoplot_multi_fold_dt.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

#' Autoplot helper
#' @param resampling Actual resampling object (needed for spcv_block with
#' "show_blocks = TRUE")
#' @param resampling_mod Modified resampling object (normal data.table)
#' @keywords internal
autoplot_multi_fold_dt = function(task, resampling, resampling_mod,
sample_fold_n, fold_id, repeats_id, plot_as_grid = FALSE,
show_omitted = FALSE, show_blocks = FALSE, show_labels = FALSE, ...) {
show_omitted = FALSE, show_blocks = FALSE, show_labels = FALSE, label_size = 2, ...) {

plot_list = mlr3misc::map(fold_id, function(.x) {

Expand Down Expand Up @@ -63,7 +62,7 @@ autoplot_multi_fold_dt = function(task, resampling, resampling_mod,
geom_sf_label(
data = blocks, color = "black",
label = blocks$fold,
size = 2, label.padding = unit(0.1, "lines"),
size = label_size, label.padding = unit(0.1, "lines"),
fun.geometry = function(x) {
# Warning: In st_point_on_surface.sfc(sf::st_zm(x)) :
# st_point_on_surface may not give correct results for
Expand Down
5 changes: 5 additions & 0 deletions man/autoplot.ResamplingSpCVBlock.Rd

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

1 change: 1 addition & 0 deletions man/autoplot_multi_fold_dt.Rd

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

0 comments on commit 3e7eeb2

Please sign in to comment.