# This file is automatically generated, you probably don't want to edit this
alluvialOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"alluvialOptions",
inherit = jmvcore::Options,
public = list(
initialize = function(
vars = NULL,
condensationvar = NULL,
excl = FALSE,
marg = FALSE,
fill = "first_variable",
bin = "default",
orient = "vert",
usetitle = FALSE,
mytitle = "Alluvial Plot", ...) {
super$initialize(
package="ClinicoPath",
name="alluvial",
requiresData=TRUE,
...)
private$..vars <- jmvcore::OptionVariables$new(
"vars",
vars)
private$..condensationvar <- jmvcore::OptionVariable$new(
"condensationvar",
condensationvar)
private$..excl <- jmvcore::OptionBool$new(
"excl",
excl,
default=FALSE)
private$..marg <- jmvcore::OptionBool$new(
"marg",
marg,
default=FALSE)
private$..fill <- jmvcore::OptionList$new(
"fill",
fill,
options=list(
"first_variable",
"last_variable",
"all_flows",
"values"),
default="first_variable")
private$..bin <- jmvcore::OptionList$new(
"bin",
bin,
options=list(
"default",
"mean",
"median",
"min_max",
"cuts"),
default="default")
private$..orient <- jmvcore::OptionList$new(
"orient",
orient,
options=list(
"horr",
"vert"),
default="vert")
private$..usetitle <- jmvcore::OptionBool$new(
"usetitle",
usetitle,
default=FALSE)
private$..mytitle <- jmvcore::OptionString$new(
"mytitle",
mytitle,
default="Alluvial Plot")
self$.addOption(private$..vars)
self$.addOption(private$..condensationvar)
self$.addOption(private$..excl)
self$.addOption(private$..marg)
self$.addOption(private$..fill)
self$.addOption(private$..bin)
self$.addOption(private$..orient)
self$.addOption(private$..usetitle)
self$.addOption(private$..mytitle)
}),
active = list(
vars = function() private$..vars$value,
condensationvar = function() private$..condensationvar$value,
excl = function() private$..excl$value,
marg = function() private$..marg$value,
fill = function() private$..fill$value,
bin = function() private$..bin$value,
orient = function() private$..orient$value,
usetitle = function() private$..usetitle$value,
mytitle = function() private$..mytitle$value),
private = list(
..vars = NA,
..condensationvar = NA,
..excl = NA,
..marg = NA,
..fill = NA,
..bin = NA,
..orient = NA,
..usetitle = NA,
..mytitle = NA)
)
alluvialResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"alluvialResults",
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
plot = function() private$.items[["plot"]],
plot2 = function() private$.items[["plot2"]]),
private = list(),
public=list(
initialize=function(options) {
super$initialize(
options=options,
name="",
title="Alluvial Diagrams",
refs=list(
"easyalluvial",
"ClinicoPathJamoviModule"))
self$add(jmvcore::Html$new(
options=options,
name="todo",
title="To Do",
clearWith=list(
"vars")))
self$add(jmvcore::Image$new(
options=options,
title="Alluvial Diagrams",
name="plot",
width=600,
height=450,
renderFun=".plot",
requiresData=TRUE,
clearWith=list(
"vars",
"excl",
"marg",
"verb",
"fill",
"bin",
"orient",
"usetitle",
"mytitle")))
self$add(jmvcore::Image$new(
options=options,
title="`Condensation Plot ${condensationvar}`",
name="plot2",
width=600,
height=450,
renderFun=".plot2",
requiresData=TRUE,
clearWith=list(
"vars",
"condensationvar"),
visible="(condensationvar)"))}))
alluvialBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
"alluvialBase",
inherit = jmvcore::Analysis,
public = list(
initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
super$initialize(
package = "ClinicoPath",
name = "alluvial",
version = c(0,0,2),
options = options,
results = alluvialResults$new(options=options),
data = data,
datasetId = datasetId,
analysisId = analysisId,
revision = revision,
pause = NULL,
completeWhenFilled = FALSE,
requiresMissings = FALSE,
weightsSupport = 'auto')
}))
#' Alluvial Diagrams
#'
#'
#' @param data The data as a data frame.
#' @param vars a string naming the variables from \code{data} that contains
#' the values used for the Alluvial Diagram.
#' @param condensationvar The primary variable to be used for condensation.
#' @param excl Exclude missing values from the analysis.
#' @param marg Include marginal plots.
#' @param fill A list for the argument fill for selecting the variable to be
#' represented by color. Default is 'first_variable'.
#' @param bin labels for the bins from low to high
#' @param orient Orientation of the plot. Default is 'vertical'.
#' @param usetitle Use a custom title for the plot.
#' @param mytitle Title for the plot.
#' @return A results object containing:
#' \tabular{llllll}{
#' \code{results$todo} \tab \tab \tab \tab \tab a html \cr
#' \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#' \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
alluvial <- function(
data,
vars,
condensationvar,
excl = FALSE,
marg = FALSE,
fill = "first_variable",
bin = "default",
orient = "vert",
usetitle = FALSE,
mytitle = "Alluvial Plot") {
if ( ! requireNamespace("jmvcore", quietly=TRUE))
stop("alluvial requires jmvcore to be installed (restart may be required)")
if ( ! missing(vars)) vars <- jmvcore::resolveQuo(jmvcore::enquo(vars))
if ( ! missing(condensationvar)) condensationvar <- jmvcore::resolveQuo(jmvcore::enquo(condensationvar))
if (missing(data))
data <- jmvcore::marshalData(
parent.frame(),
`if`( ! missing(vars), vars, NULL),
`if`( ! missing(condensationvar), condensationvar, NULL))
options <- alluvialOptions$new(
vars = vars,
condensationvar = condensationvar,
excl = excl,
marg = marg,
fill = fill,
bin = bin,
orient = orient,
usetitle = usetitle,
mytitle = mytitle)
analysis <- alluvialClass$new(
options = options,
data = data)
analysis$run()
analysis$results
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.