Skip to content

Commit 1c226e1

Browse files
committed
added easyalluvial. for condensation variable there is a bug self$data is selected as other variables
1 parent b92489b commit 1c226e1

20 files changed

+377
-82
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ Depends:
2525
R (>= 3.6.0)
2626
Imports:
2727
jmvcore,
28-
R6
28+
R6,
29+
magrittr
2930
Remotes:
3031
ddsjoberg/gtsummary,
3132
ndphillips/FFTrees,
@@ -56,7 +57,6 @@ Suggests:
5657
explore,
5758
rpart,
5859
rpart.plot,
59-
magrittr,
6060
plotROC,
6161
arsenal,
6262
easyalluvial,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export(vartree)
2525
import(jmvcore)
2626
importFrom(R6,R6Class)
2727
importFrom(jmvcore,toNumeric)
28+
importFrom(magrittr,"%>%")
2829
importFrom(utils,data)

R/alluvial.b.R

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
#' @title Alluvial Plot
2+
#' @return Alluvial Plot
3+
#' @importFrom R6 R6Class
4+
#' @import jmvcore
5+
#' @importFrom magrittr %>%
6+
#'
7+
18

29
# This file is a generated template, your changes will not be overwritten
310

@@ -36,15 +43,6 @@ alluvialClass <- if (requireNamespace('jmvcore')) R6::R6Class(
3643

3744

3845

39-
40-
41-
42-
43-
44-
45-
46-
47-
4846
# #Errors ----
4947
#
5048
# if (is.null(self$options$vars) )
@@ -106,29 +104,6 @@ alluvialClass <- if (requireNamespace('jmvcore')) R6::R6Class(
106104
# html$setContent(plothtml)
107105

108106

109-
110-
111-
112-
113-
114-
115-
116-
117-
118-
119-
120-
121-
122-
123-
124-
125-
126-
127-
128-
129-
130-
131-
132107
}
133108

134109
}
@@ -161,20 +136,20 @@ alluvialClass <- if (requireNamespace('jmvcore')) R6::R6Class(
161136

162137
verbose <- FALSE
163138

139+
verb <- self$options$verb
140+
164141
if (isTRUE(verb)) verbose <- TRUE
165142

166143
# fill_by ----
167144

168-
jmvcore::composeTerm(self$options$fill)
169-
170-
self$options$fill
145+
fill <- jmvcore::composeTerm(self$options$fill)
171146

172147

173148
#bin
174149

175150
bin <- self$options$bin
176151

177-
if (bin = "default") bin <- 'c("LL", "ML", "M", "MH", "HH")'
152+
if (bin == "default") bin <- c("LL", "ML", "M", "MH", "HH")
178153

179154
# Exclude NA ----
180155

@@ -223,5 +198,48 @@ alluvialClass <- if (requireNamespace('jmvcore')) R6::R6Class(
223198
print(plot)
224199
TRUE
225200

226-
})
201+
}
202+
203+
204+
,
205+
206+
.plot2 = function(image, ...) {
207+
# the plot function ----
208+
209+
#Errors ----
210+
211+
if (is.null(self$options$condensationvar) )
212+
return()
213+
214+
if (nrow(self$data) == 0)
215+
stop('Data contains no (complete) rows')
216+
217+
# Prepare Data ----
218+
219+
condvarName <- self$options$condensationvar
220+
221+
condvarName <- jmvcore::composeTerm(components = condvarName)
222+
223+
224+
225+
plot2 <- self$data %>%
226+
easyalluvial::plot_condensation(df = .,
227+
first = .data[[condvarName]])
228+
229+
230+
# Print Plot ----
231+
232+
print(plot2)
233+
TRUE
234+
235+
236+
237+
238+
}
239+
240+
241+
242+
243+
244+
)
227245
)

R/alluvial.h.R

Lines changed: 83 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ alluvialOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
77
public = list(
88
initialize = function(
99
vars = NULL,
10+
condensationvar = NULL,
1011
excl = TRUE,
11-
marg = FALSE, ...) {
12+
marg = FALSE,
13+
verb = FALSE,
14+
fill = "first_variable",
15+
bin = "default", ...) {
1216

1317
super$initialize(
1418
package='ClinicoPath',
@@ -19,6 +23,9 @@ alluvialOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
1923
private$..vars <- jmvcore::OptionVariables$new(
2024
"vars",
2125
vars)
26+
private$..condensationvar <- jmvcore::OptionVariable$new(
27+
"condensationvar",
28+
condensationvar)
2229
private$..excl <- jmvcore::OptionBool$new(
2330
"excl",
2431
excl,
@@ -27,26 +34,62 @@ alluvialOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
2734
"marg",
2835
marg,
2936
default=FALSE)
37+
private$..verb <- jmvcore::OptionBool$new(
38+
"verb",
39+
verb,
40+
default=FALSE)
41+
private$..fill <- jmvcore::OptionList$new(
42+
"fill",
43+
fill,
44+
options=list(
45+
"first_variable",
46+
"last_variable",
47+
"all_flows",
48+
"values"),
49+
default="first_variable")
50+
private$..bin <- jmvcore::OptionList$new(
51+
"bin",
52+
bin,
53+
options=list(
54+
"default",
55+
"mean",
56+
"median",
57+
"min_max",
58+
"cuts"),
59+
default="default")
3060

3161
self$.addOption(private$..vars)
62+
self$.addOption(private$..condensationvar)
3263
self$.addOption(private$..excl)
3364
self$.addOption(private$..marg)
65+
self$.addOption(private$..verb)
66+
self$.addOption(private$..fill)
67+
self$.addOption(private$..bin)
3468
}),
3569
active = list(
3670
vars = function() private$..vars$value,
71+
condensationvar = function() private$..condensationvar$value,
3772
excl = function() private$..excl$value,
38-
marg = function() private$..marg$value),
73+
marg = function() private$..marg$value,
74+
verb = function() private$..verb$value,
75+
fill = function() private$..fill$value,
76+
bin = function() private$..bin$value),
3977
private = list(
4078
..vars = NA,
79+
..condensationvar = NA,
4180
..excl = NA,
42-
..marg = NA)
81+
..marg = NA,
82+
..verb = NA,
83+
..fill = NA,
84+
..bin = NA)
4385
)
4486

4587
alluvialResults <- if (requireNamespace('jmvcore')) R6::R6Class(
4688
inherit = jmvcore::Group,
4789
active = list(
4890
todo = function() private$.items[["todo"]],
49-
plot = function() private$.items[["plot"]]),
91+
plot = function() private$.items[["plot"]],
92+
plot2 = function() private$.items[["plot2"]]),
5093
private = list(),
5194
public=list(
5295
initialize=function(options) {
@@ -64,7 +107,9 @@ alluvialResults <- if (requireNamespace('jmvcore')) R6::R6Class(
64107
"vars",
65108
"excl",
66109
"marg",
67-
"inter")))
110+
"verb",
111+
"fill",
112+
"bin")))
68113
self$add(jmvcore::Image$new(
69114
options=options,
70115
title="Alluvial Diagrams",
@@ -77,7 +122,20 @@ alluvialResults <- if (requireNamespace('jmvcore')) R6::R6Class(
77122
"vars",
78123
"excl",
79124
"marg",
80-
"inter")))}))
125+
"verb",
126+
"fill",
127+
"bin")))
128+
self$add(jmvcore::Image$new(
129+
options=options,
130+
title="`Condensation Plot ${condensationvar}`",
131+
name="plot2",
132+
width=600,
133+
height=450,
134+
renderFun=".plot2",
135+
requiresData=TRUE,
136+
clearWith=list(
137+
"condensationvar"),
138+
visible="(condensationvar)"))}))
81139

82140
alluvialBase <- if (requireNamespace('jmvcore')) R6::R6Class(
83141
"alluvialBase",
@@ -105,35 +163,51 @@ alluvialBase <- if (requireNamespace('jmvcore')) R6::R6Class(
105163
#' @param data The data as a data frame.
106164
#' @param vars a string naming the variables from \code{data} that contains
107165
#' the values used for the Alluvial Diagram.
166+
#' @param condensationvar The primary variable to be used for condensation.
108167
#' @param excl .
109168
#' @param marg .
169+
#' @param verb .
170+
#' @param fill A list for the argument fill for selecting the variable to be
171+
#' represented by color. Default is 'first_variable'.
172+
#' @param bin labels for the bins from low to high
110173
#' @return A results object containing:
111174
#' \tabular{llllll}{
112175
#' \code{results$todo} \tab \tab \tab \tab \tab a html \cr
113176
#' \code{results$plot} \tab \tab \tab \tab \tab an image \cr
177+
#' \code{results$plot2} \tab \tab \tab \tab \tab an image \cr
114178
#' }
115179
#'
116180
#' @export
117181
alluvial <- function(
118182
data,
119183
vars,
184+
condensationvar,
120185
excl = TRUE,
121-
marg = FALSE) {
186+
marg = FALSE,
187+
verb = FALSE,
188+
fill = "first_variable",
189+
bin = "default") {
122190

123191
if ( ! requireNamespace('jmvcore'))
124192
stop('alluvial requires jmvcore to be installed (restart may be required)')
125193

126194
if ( ! missing(vars)) vars <- jmvcore::resolveQuo(jmvcore::enquo(vars))
195+
if ( ! missing(condensationvar)) condensationvar <- jmvcore::resolveQuo(jmvcore::enquo(condensationvar))
127196
if (missing(data))
128197
data <- jmvcore::marshalData(
129198
parent.frame(),
130-
`if`( ! missing(vars), vars, NULL))
199+
`if`( ! missing(vars), vars, NULL),
200+
`if`( ! missing(condensationvar), condensationvar, NULL))
131201

132202

133203
options <- alluvialOptions$new(
134204
vars = vars,
205+
condensationvar = condensationvar,
135206
excl = excl,
136-
marg = marg)
207+
marg = marg,
208+
verb = verb,
209+
fill = fill,
210+
bin = bin)
137211

138212
analysis <- alluvialClass$new(
139213
options = options,

R/crosstable.b.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ crosstableClass <- if (requireNamespace('jmvcore')) R6::R6Class(
104104
# myvars <- unlist(myvars)
105105

106106
mydata %>%
107-
summary_factorlist(dependent = self$options$group,
107+
finalfit::summary_factorlist(
108+
.data = .,
109+
dependent = self$options$group,
108110
explanatory = myvars,
109111
# column = TRUE,
110112
total_col = TRUE,

R/multisurvival.b.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ multisurvivalClass <- if (requireNamespace('jmvcore')) R6::R6Class(
144144
formulaR <- jmvcore::toNumeric(formulaR)
145145

146146

147-
myformula <- paste("Surv(", formulaL, ",", formulaR, ")")
147+
myformula <- paste("survival::Surv(", formulaL, ",", formulaR, ")")
148148

149149

150150
# https://finalfit.org/reference/hr_plot.html
@@ -204,7 +204,7 @@ multisurvivalClass <- if (requireNamespace('jmvcore')) R6::R6Class(
204204

205205
formula2 <- jmvcore::constructFormula(terms = self$options$explanatory)
206206

207-
formula3 <- paste("Surv(", formulaL, ",", formulaR, ") ~ ", formula2)
207+
formula3 <- paste("survival::Surv(", formulaL, ",", formulaR, ") ~ ", formula2)
208208

209209
formula3 <- as.formula(formula3)
210210

R/reportcat.b.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#' @title Summary of Categorical Variables
2-
#'
3-
#'
4-
#'
2+
#' @return Text
53
#'
64
#' @importFrom R6 R6Class
75
#' @import jmvcore
6+
#' @importFrom magrittr %>%
87
#'
98

109
reportcatClass <- if (requireNamespace('jmvcore')) R6::R6Class(

README.Rmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ https://osf.io/9szud/
131131
🔬🔬🔬🔬 UNDER CONSTRUCTION 🛠⛔️⚠️🔩
132132

133133

134+
135+
136+
#### Alluvial Diagrams
137+
138+
🔬🔬🔬🔬 UNDER CONSTRUCTION 🛠⛔️⚠️🔩
139+
140+
141+
<img src="man/figures/jamovi-ClinicoPath-easyalluvial.gif" align="center" width = 75% />
142+
143+
144+
145+
134146
---
135147

136148
### Comparisons

0 commit comments

Comments
 (0)