Skip to content

Commit

Permalink
WIP jjstatsplot functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalci committed Jun 7, 2020
1 parent bccf767 commit f20ac2a
Show file tree
Hide file tree
Showing 65 changed files with 3,391 additions and 4,580 deletions.
5 changes: 0 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ Suggests:
gtsummary,
vctrs,
patchwork
Remotes:
ndphillips/FFTrees,
easystats/report,
spgarbet/tangram,
cran/rmngb
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
15 changes: 1 addition & 14 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

export(agreement)
export(alluvial)
export(bartlett_message)
export(competingsurvival)
export(correlation)
export(crosstable)
Expand All @@ -11,8 +10,8 @@ export(decisioncalculator)
export(gtsummary)
export(icccoeff)
export(jjbarstats)
export(jjbarstats2)
export(jjbetweenstats)
export(jjcoefstats)
export(jjcorrmat)
export(jjdotplotstats)
export(jjhistostats)
Expand All @@ -21,7 +20,6 @@ export(jjscatterstats)
export(jjwithinstats)
export(jviolin)
export(multisurvival)
export(normality_message)
export(oddsratio)
export(pairchi2)
export(reportcat)
Expand All @@ -35,17 +33,6 @@ export(vartree)
import(ggplot2)
import(jmvcore)
importFrom(R6,R6Class)
importFrom(crayon,blue)
importFrom(crayon,green)
importFrom(crayon,red)
importFrom(crayon,yellow)
importFrom(jmvcore,toNumeric)
importFrom(magrittr,"%>%")
importFrom(rlang,":=")
importFrom(rlang,as_name)
importFrom(rlang,ensym)
importFrom(rlang,new_formula)
importFrom(stats,bartlett.test)
importFrom(stats,na.omit)
importFrom(stats,shapiro.test)
importFrom(utils,data)
74 changes: 49 additions & 25 deletions R/jjbarstats.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jjbarstatsClass <- if (requireNamespace('jmvcore')) R6::R6Class(
# TODO ----

todo <- glue::glue(
"
<br>Welcome to ClinicoPath
"<br>Welcome to ClinicoPath
<br><br>
This tool will help you generate Bar Charts.
<br><br>
Expand Down Expand Up @@ -98,27 +97,37 @@ jjbarstatsClass <- if (requireNamespace('jmvcore')) R6::R6Class(



mydep <- mydata[[self$options$dep]]
# mydep <- mydata[[self$options$dep]]
# mygroup <- mydata[[self$options$group]]

mygroup <- mydata[[self$options$group]]

dep <- self$options$dep

group <- self$options$group


dep <- jmvcore::composeTerm(components = dep)

group <- jmvcore::composeTerm(components = group)


# ggbarstats ----
# bar charts for categorical data
# https://indrajeetpatil.github.io/ggstatsplot/reference/ggbarstats.html


plotData <- data.frame(gr = mygroup,
dp = mydep)

plot <-
ggstatsplot::ggbarstats(
data = mydata,
main = !!dep,
condition = !!group,

paired = paired,

plot <- ggstatsplot::ggbarstats(data = plotData,
main = dp,
condition = gr,

counts = NULL,
ratio = NULL,
paired = paired,
results.subtitle = TRUE,
sample.size.label = TRUE,
label = "percentage",
Expand Down Expand Up @@ -171,10 +180,22 @@ jjbarstatsClass <- if (requireNamespace('jmvcore')) R6::R6Class(

# Prepare Data ----

mydata <- self$data


# direction, paired ----

mydata <- self$data
direction <- self$options$direction

if (direction == "repeated") {

paired <- TRUE

} else if (direction == "independent") {

paired <- FALSE

}

# Exclude NA ----

Expand All @@ -184,33 +205,36 @@ jjbarstatsClass <- if (requireNamespace('jmvcore')) R6::R6Class(



mydep <- mydata[[self$options$dep]]
dep <- self$options$dep

group <- self$options$group


dep <- jmvcore::composeTerm(components = dep)

group <- jmvcore::composeTerm(components = group)



mygroup <- mydata[[self$options$group]]

# grouped_ggbarstats ----
# https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggbarstats.html



if ( !is.null(self$options$grvar) ) {
mygrvar <- mydata[[self$options$grvar]]
}

grvar <- self$options$grvar

if ( !is.null(self$options$grvar) ) {
plot2 <- ggstatsplot::grouped_ggbarstats(
data = mydata,
main = !!dep,
condition = !!group,
grouping.var = !!grvar,

plotData <- data.frame(gr = mygroup,
dp = mydep,
grvar = mygrvar)
paired = paired,


plot2 <- ggstatsplot::grouped_ggbarstats(
data = plotData,
main = dp,
condition = gr,
counts = NULL,
grouping.var = grvar,
title.prefix = NULL,
output = "plot",
x = NULL,
Expand Down
24 changes: 12 additions & 12 deletions R/jjbarstats.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ jjbarstatsResults <- if (requireNamespace('jmvcore')) R6::R6Class(
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
plot = function() private$.items[["plot"]],
plot2 = function() private$.items[["plot2"]]),
plot2 = function() private$.items[["plot2"]],
plot = function() private$.items[["plot"]]),
private = list(),
public=list(
initialize=function(options) {
Expand All @@ -101,31 +101,31 @@ jjbarstatsResults <- if (requireNamespace('jmvcore')) R6::R6Class(
"direction")))
self$add(jmvcore::Image$new(
options=options,
name="plot",
title="`Bar Chart ${group} - {dep}`",
name="plot2",
title="`Bar Chart ${group} - {dep} by {grvar}`",
width=800,
height=600,
renderFun=".plot",
renderFun=".plot2",
requiresData=TRUE,
clearWith=list(
"dep",
"group",
"grvar",
"direction")))
"direction"),
visible="(grvar)"))
self$add(jmvcore::Image$new(
options=options,
name="plot2",
title="`Bar Chart ${group} - {dep} by {grvar}`",
name="plot",
title="`Bar Chart ${group} - {dep}`",
width=800,
height=600,
renderFun=".plot2",
renderFun=".plot",
requiresData=TRUE,
clearWith=list(
"dep",
"group",
"grvar",
"direction"),
visible="(grvar)"))}))
"direction")))}))

jjbarstatsBase <- if (requireNamespace('jmvcore')) R6::R6Class(
"jjbarstatsBase",
Expand Down Expand Up @@ -166,8 +166,8 @@ jjbarstatsBase <- if (requireNamespace('jmvcore')) R6::R6Class(
#' @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
#' \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#' }
#'
#' @export
Expand Down
Loading

0 comments on commit f20ac2a

Please sign in to comment.