R/mds_test_plot.R

Defines functions plot_mds_test

Documented in plot_mds_test

#' Plot [mds_test()] results
#'
#' `r lifecycle::badge('experimental')`  Plot output from [mds_test()].
#'
#' @importFrom ggplot2 ggplot geom_boxplot geom_point labs
#' @importFrom dplyr filter
#'
#' @param mds_test Object of class `mds_test_results` (generated by [mds_test()]).
#'
#' @return `ggplot` object.
#' @export
#'
#' @examples
#' mds_result <- mds_test(
#'     sim_matrix,
#'     n_boots = 10,
#'     n_perms = 10,
#'     test_dimensions = 3,
#'     mds_type = 'interval'
#'  )
#'  plot_mds_test(mds_result)
plot_mds_test <- function(mds_test) {
  mds_test$stress_reduction |>
    filter(
      .data$source != "original"
    ) |>
    ggplot(
      aes(
        x = factor(.data$dims),
        y = diff,
        colour = factor(.data$source, labels = c("Bootstrapped", "Null"))
      )
    ) +
    geom_boxplot() +
    geom_point(
      data = mds_test$stress_reduction |>
       filter(.data$source == "original"),
      colour = "black",
      shape = 4,
      size = 5,
      stroke = 2
    ) +
    labs(
      colour = "Source",
      x = "Dimensions",
      y = "Stress reduction"
    )
}

Try the nzilbb.vowels package in your browser

Any scripts or data that you put into this service are public.

nzilbb.vowels documentation built on June 8, 2025, 12:35 p.m.