Examples in 3D: part I

This vignette contains part I of a set of examples on how to use clugenr in 3D. Examples require the following setup code:

library(clugenr)    # The clugenr library
options(rgl.useNULL = TRUE)  # Create RGL plots in systems without displays (CI)
library(rgl)
setupKnitr(autoprint = TRUE) # Render RGL plots directly on generated page

# Load helper functions for plotting examples
source("plot_examples_3d.R", local = knitr::knit_global())

# Keep examples reproducible in newer R versions
RNGversion("3.6.0")

The 3D examples were plotted with the plot_examples_3d() function available here.

Manipulating the direction of cluster-supporting lines

Using the direction parameter

seed <- 123
e040 <- clugen(3, 4, 500, c(1, 0, 0), 0, c(10, 10, 10), 15, 1.5, 0.5, seed = seed)
e041 <- clugen(3, 4, 500, c(1, 1, 1), 0, c(10, 10, 10), 15, 1.5, 0.5, seed = seed)
e042 <- clugen(3, 4, 500, c(0, 0, 1), 0, c(10, 10, 10), 15, 1.5, 0.5, seed = seed)
plot_examples_3d(list(e = e040, t = "e040: direction = [1, 0, 0]"),
                 list(e = e041, t = "e041: direction = [1, 1, 1]"),
                 list(e = e042, t = "e042: direction = [0, 0, 1]"))

Changing the angle_disp parameter and using a custom angle_deltas_fn function

seed <- 123
# Custom angle_deltas function: arbitrarily rotate some clusters by 90 degrees
angdel_90 <- function(nclu, astd) sample(c(0, pi / 2), nclu, replace = TRUE)
e043 <- clugen(3, 6, 1000, c(1, 0, 0), 0, c(10, 10, 10), 15, 1.5, 0.5, seed = seed)
e044 <- clugen(3, 6, 1000, c(1, 0, 0), pi / 8, c(10, 10, 10), 15, 1.5, 0.5, seed = seed)
e045 <- clugen(3, 6, 1000, c(1, 0, 0), 0, c(10, 10, 10), 15, 1.5, 0.5, seed = seed,
              angle_deltas_fn = angdel_90)
plot_examples_3d(list(e = e043, t = "e043: angle_disp = 0"),
                 list(e = e044, t = "e044: angle_disp = π / 8"),
                 list(e = e045, t = "e045: custom angle_deltas function"))

Specifying a main direction for each cluster and changing angle_disp

seed <- 123
# Define a main direction for each cluster
dirs <- matrix(c(1, 1, 1,
                 0, 0, 1,
                 1, 0, 0,
                 0, 1, 0,
                 -1, 1, 1),
               nrow = 5, byrow = TRUE)
e046 <- clugen(3, 5, 1000, dirs, 0, rep.int(0, 3), 20, 0, 0.25, seed = seed)
e047 <- clugen(3, 5, 1000, dirs, pi / 12, rep.int(0, 3), 20, 0, 0.25, seed = seed)
e048 <- clugen(3, 5, 1000, dirs, pi / 4, rep.int(0, 3), 20, 0, 0.25, seed = seed)
plot_examples_3d(list(e = e046, t = "e046: angle_disp = 0"),
                 list(e = e047, t = "e047: angle_disp = π / 12"),
                 list(e = e048, t = "e048: angle_disp = π / 4"))

Manipulating the length of cluster-supporting lines

seed <- 123

Using the llength parameter

e049 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 0, 0, 0.5,
              seed = seed, point_dist_fn = "n")
e050 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 10, 0, 0.5,
              seed = seed, point_dist_fn = "n")
e051 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 30, 0, 0.5,
              seed = seed, point_dist_fn = "n")
plot_examples_3d(list(e = e049, t = "e049: llength = 0"),
                 list(e = e050, t = "e050: llength = 10"),
                 list(e = e051, t = "e051: llength = 30"))

Changing the llength_disp parameter and using a custom llengths_fn function

# Custom llengths function: line lengths tend to grow for each new cluster
llen_grow <- function(nclu, llen, llenstd) {
  llen * (0:(nclu - 1) + rnorm(nclu, sd = llenstd))
}
e052 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 15,  0.0, 0.5,
              seed = seed, point_dist_fn = "n")
e053 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 15, 10.0, 0.5,
              seed = seed, point_dist_fn = "n")
e054 <- clugen(3, 5, 800, c(1, 0, 0), pi / 10, c(10, 10, 10), 10,  0.1, 0.5,
              seed = seed, point_dist_fn = "n", llengths_fn = llen_grow)
plot_examples_3d(list(e = e052, t = "e052: llength_disp = 0.0"),
                 list(e = e053, t = "e053: llength_disp = 10.0"),
                 list(e = e054, t = "e054: custom llengths function"))

Manipulating relative cluster positions

Using the cluster_sep parameter

seed <- 321
e055 <- clugen(3, 8, 1000, c(1, 1, 1), pi / 4, c(30, 10, 10), 25, 4, 3, seed = seed)
e056 <- clugen(3, 8, 1000, c(1, 1, 1), pi / 4, c(10, 30, 10), 25, 4, 3, seed = seed)
e057 <- clugen(3, 8, 1000, c(1, 1, 1), pi / 4, c(10, 10, 30), 25, 4, 3, seed = seed)
plot_examples_3d(list(e = e055, t = "e055: cluster_sep = [30, 10, 10]"),
                 list(e = e056, t = "e056: cluster_sep = [10, 30, 10]"),
                 list(e = e057, t = "e057: cluster_sep = [10, 10, 30]"))