autoplot.ResamplingSpCVBlock: Visualization Functions for SpCV Block Methods.

Description Usage Arguments Details Value See Also Examples

View source: R/autoplot.R

Description

Generic S3 plot() and autoplot() (ggplot2) methods to visualize mlr3 spatiotemporal resampling objects.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
## S3 method for class 'ResamplingSpCVBlock'
autoplot(
  object,
  task,
  fold_id = NULL,
  plot_as_grid = TRUE,
  train_color = "#0072B5",
  test_color = "#E18727",
  crs = NULL,
  show_blocks = FALSE,
  show_labels = FALSE,
  ...
)

## S3 method for class 'ResamplingRepeatedSpCVBlock'
autoplot(
  object,
  task,
  fold_id = NULL,
  repeats_id = 1,
  plot_as_grid = TRUE,
  train_color = "#0072B5",
  test_color = "#E18727",
  crs = NULL,
  show_blocks = FALSE,
  show_labels = FALSE,
  ...
)

## S3 method for class 'ResamplingSpCVBlock'
plot(x, ...)

## S3 method for class 'ResamplingRepeatedSpCVBlock'
plot(x, ...)

Arguments

object

[Resampling]
mlr3 spatial resampling object of class ResamplingSpCVBlock or ResamplingRepeatedSpCVBlock.

task

[TaskClassifST]/[TaskRegrST]
mlr3 task object.

fold_id

[numeric]
Fold IDs to plot.

plot_as_grid

[logical(1)]
Should a gridded plot using via patchwork be created? If FALSE a list with of ggplot2 objects is returned. Only applies if a numeric vector is passed to argument fold_id.

train_color

[character(1)]
The color to use for the training set observations.

test_color

[character(1)]
The color to use for the test set observations.

crs

[character]
EPSG code of the CRS for x and y axes.

show_blocks

[logical(1)]
Whether to show an overlay of the spatial blocks polygons.

show_labels

[logical(1)]
Whether to show an overlay of the spatial block IDs.

...

Passed to geom_sf(). Helpful for adjusting point sizes and shapes.

repeats_id

[numeric]
Repetition ID to plot.

x

[Resampling]
mlr3 spatial resampling object. One of class ResamplingSpCVBuffer, ResamplingSpCVBlock, ResamplingSpCVCoords, ResamplingSpCVEnv.

Details

By default a plot is returned; if fold_id is set, a gridded plot is created. If plot_as_grid = FALSE, a list of plot objects is returned. This can be used to align the plots individually.

When no single fold is selected, the ggsci::scale_color_ucscgb() palette is used to display all partitions. If you want to change the colors, call <plot> + <color-palette>().

Value

ggplot() or list of ggplot2 objects.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
if (mlr3misc::require_namespaces(c("sf", "blockCV"), quietly = TRUE)) {
  library(mlr3)
  library(mlr3spatiotempcv)
  task = tsk("ecuador")
  resampling = rsmp("spcv_block", range = 1000L)
  resampling$instantiate(task)

  ## list of ggplot2 resamplings
  plot_list = autoplot(resampling, task,
    crs = 4326,
    fold_id = c(1, 2), plot_as_grid = FALSE)

  ## Visualize all partitions
  autoplot(resampling, task, crs = 4326) +
    ggplot2::scale_x_continuous(breaks = seq(-79.085, -79.055, 0.01))

  ## Visualize the train/test split of a single fold
  autoplot(resampling, task, fold_id = 1, crs = 4326) +
    ggplot2::scale_x_continuous(breaks = seq(-79.085, -79.055, 0.01))

  ## Visualize train/test splits of multiple folds
  autoplot(resampling, task,
    fold_id = c(1, 2), crs = 4326,
    show_blocks = TRUE) *
    ggplot2::scale_x_continuous(breaks = seq(-79.085, -79.055, 0.01))
}

mlr-org/mlr3spatiotempcv documentation built on May 4, 2021, 9:44 a.m.