{mlr3spatiotempcv} makes use of {plotly} to create the 3D plots for visualizing spatiotemporal folds created via the CLUTO algorithm. Arranging multiple 3D plots in {plotly} is done via 3D subplots.

Unfortunately, {plotly}’s subplot implementation is not dynamic. This means that multiple “scene” objects need to be specified in plotly::layout() to determine the coordinates of the respective subplot. Depending on the number of chosen folds by the user in autoplot(), a different number of scenes with different coordinates needs to be given to align the plots properly.

Hence, manual action is needed to create a properly aligned grid of 3D plots.

Below is an example how to create a 2x2 grid showing four folds as 3D subplots. It makes use of the returned 3D plotly objects which are returned in a list by autoplot():

library(mlr3)
library(mlr3spatiotempcv)
task_st = tsk("cookfarm")
resampling = rsmp("sptcv_cluto", folds = 5, time_var = "Date")
resampling$instantiate(task_st)
#> ********************************************************************************
#> vcluster (CLUTO 2.1.2) Copyright 2001-06, Regents of the University of Minnesota
#> 
#> Matrix Information -----------------------------------------------------------
#>   Name: /tmp/RtmpFBs5ub/file4e02795f80c1, #Rows: 500, #Columns: 3, #NonZeros: 1500
#> 
#> Options ----------------------------------------------------------------------
#>   CLMethod=Direct, CRfun=I2, SimFun=Cosine, #Clusters: 5
#>   RowModel=None, ColModel=None, GrModel=SY-DIR, NNbrs=40
#>   Colprune=1.00, EdgePrune=-1.00, VtxPrune=-1.00, MinComponent=5
#>   CSType=Best, AggloFrom=0, AggloCRFun=I2, NTrials=10, NIter=10
#> 
#> Solution ---------------------------------------------------------------------
#> 
#> ------------------------------------------------------------------------
#> 5-way clustering: [I2=5.00e+02] [500 of 500]
#> ------------------------------------------------------------------------
#> cid  Size  ISim  ISdev   ESim  ESdev  | 
#> ------------------------------------------------------------------------
#>   0    97 +1.000 +0.000 +1.000 +0.000 | 
#>   1    92 +1.000 +0.000 +1.000 +0.000 | 
#>   2    91 +1.000 +0.000 +1.000 +0.000 | 
#>   3   101 +1.000 +0.000 +1.000 +0.000 | 
#>   4   119 +1.000 +0.000 +1.000 +0.000 | 
#> ------------------------------------------------------------------------
#> 
#> Timing Information -----------------------------------------------------------
#>    I/O:                                   0.001 sec
#>    Clustering:                            0.002 sec
#>    Reporting:                             0.000 sec
#> Memory Usage Information -----------------------------------------------------
#>    Maximum memory used:                   86016 bytes
#>    Current memory used:                   51608 bytes
#> ********************************************************************************

pl = plot(resampling, task_st, c(1, 2, 3, 4),
  point_size = 3, axis_label_fontsize = 10)
#> CRS not set, transforming to WGS84 (EPSG: 4326).
#> Unfortunately plotly does not support a dynamic arrangement of multiple
#> subplots. See article 'Visualization of spatiotemporal clusters'
#> (https://mlr3spatiotempcv.mlr-org.com/articles/spatiotemp-viz) for a
#> manual workaround. Use the objects in the returned list to arrange a
#> custom grid.
#> [[1]]
#> 
#> [[2]]
#> 
#> [[3]]
#> 
#> [[4]]

# Warnings can be ignored
pl_subplot = plotly::subplot(pl)

plotly::layout(pl_subplot,
  title = "Individual Folds",
  scene = list(
    domain = list(x = c(0, 0.5), y = c(0.5, 1)),
    aspectmode = "cube",
    camera = list(eye = list(z = 2.5))
  ),
  scene2 = list(
    domain = list(x = c(0.5, 1), y = c(0.5, 1)),
    aspectmode = "cube",
    camera = list(eye = list(z = 2.5))
  ),
  scene3 = list(
    domain = list(x = c(0, 0.5), y = c(0, 0.5)),
    aspectmode = "cube",
    camera = list(eye = list(z = 2.5))
  ),
  scene4 = list(
    domain = list(x = c(0.5, 1), y = c(0, 0.5)),
    aspectmode = "cube",
    camera = list(eye = list(z = 2.5))
  )
)
#> Warning: 'layout' objects don't have these attributes: 'NA'
#> Valid attributes include:
#> 'font', 'title', 'uniformtext', 'autosize', 'width', 'height', 'margin', 'computed', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'showlegend', 'colorway', 'datarevision', 'uirevision', 'editrevision', 'selectionrevision', 'template', 'modebar', 'newshape', 'activeshape', 'meta', 'transition', '_deprecated', 'clickmode', 'dragmode', 'hovermode', 'hoverdistance', 'spikedistance', 'hoverlabel', 'selectdirection', 'grid', 'calendar', 'xaxis', 'yaxis', 'ternary', 'scene', 'geo', 'mapbox', 'polar', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'editType', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'sliders', 'colorscale', 'coloraxis', 'metasrc', 'barmode', 'bargap', 'mapType'

(The actual graphic here is only rendered on the pkgdown site: please visit https://mlr3spatiotempcv.mlr-org.com.)

Subplot titles can unfortunately not created dynamically. However, there is also a manual workaround via annotations show in this RPubs post.