Skip to content

Commit

Permalink
jjstatsplot functions working with defaluts
Browse files Browse the repository at this point in the history
  • Loading branch information
sbalci committed Jun 9, 2020
1 parent f20ac2a commit 94e1eaf
Show file tree
Hide file tree
Showing 60 changed files with 928 additions and 1,998 deletions.
45 changes: 45 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
options(repos = c("https://cran.microsoft.com/snapshot/2020-05-01"))
# source("renv/activate.R")

# 'https://repo.jamovi.org'

# "/Users/serdarbalciold/Library/R/3.6/library"
# "/Library/Frameworks/R.framework/Versions/3.6/Resources/library"

.libPaths(new = "~/histopathRprojects/ClinicoPathLibrary")

# source(
# "renv/activate.R"
# "~/histopathRprojects/ClinicoPath/renv/activate.R"
# # here::here("renv/activate.R")
# )


# https://stackoverflow.com/questions/2096473/r-determine-if-a-script-is-running-in-windows-or-linux

# https://conjugateprior.org/2015/06/identifying-the-os-from-r/


# if (.Platform$OS.type == "windows") {
#
# if (!requireNamespace('jmvtools')) install.packages('jmvtools', repos=c('https://repo.jamovi.org', 'https://cran.r-project.org'))
#
# library("jmvtools")
#
# jmvtools::check("C://Program Files//jamovi//bin")
#
# .libPaths(new = "C:\\ClinicoPathLibrary")
#
# Sys.setenv(TZ = "Europe/Istanbul")
#
# }


.First <- function(){
cat("\nWelcome to ClinicoPath", date(), "\n")
}


.Last <- function(){
cat("\nGoodbye at ", date(), "\n")
}

9 changes: 7 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: ClinicoPath
Title: Analysis for Clinicopathological Research
Version: 0.0.2.0011
Date: 2020-06-05
Version: 0.0.2.0012
Date: 2020-06-09
Authors@R:
person(given = "Serdar",
family = "Balci",
Expand Down Expand Up @@ -72,6 +72,11 @@ Suggests:
gtsummary,
vctrs,
patchwork
Remotes:
ndphillips/FFTrees,
easystats/report,
spgarbet/tangram,
cran/rmngb
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion R/jjbarstats.b.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jjbarstatsClass <- if (requireNamespace('jmvcore')) R6::R6Class(
<br><br>
This tool will help you generate Bar Charts.
<br><br>
This function uses ggplot2 and ggstatsplot packages. See documentations <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/ggbarstats.html' target='_blank'>here</a> and <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggbarstats.html' target='_blank'>here</a>.
This function uses ggplot2 and ggstatsplot packages. See documentations <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/ggbarstats.html' target='_blank'>ggbarstats</a> and <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggbarstats.html' target='_blank'>grouped_ggbarstats</a>.
<br>
Please cite jamovi and the packages as given below.
<br><hr>"
Expand Down
2 changes: 1 addition & 1 deletion R/jjbetweenstats.b.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title jjbetweenstats
#' @title Violin Plots to Compare Between Groups
#'
#'
#'
Expand Down
6 changes: 2 additions & 4 deletions R/jjbetweenstats.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ jjbetweenstatsOptions <- if (requireNamespace('jmvcore')) R6::R6Class(
"dep",
dep,
suggested=list(
"ordinal",
"nominal"),
"continuous"),
permitted=list(
"factor"))
"numeric"))
private$..group <- jmvcore::OptionVariable$new(
"group",
group,
Expand Down Expand Up @@ -191,7 +190,6 @@ jjbetweenstats <- function(
`if`( ! missing(group), group, NULL),
`if`( ! missing(grvar), grvar, NULL))

for (v in dep) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
for (v in group) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])
for (v in grvar) if (v %in% names(data)) data[[v]] <- as.factor(data[[v]])

Expand Down
178 changes: 86 additions & 92 deletions R/jjcorrmat.b.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title jjcorrmat
#' @title Correlation Matrix
#'
#'
#' @importFrom R6 R6Class
Expand All @@ -14,16 +14,16 @@ jjcorrmatClass <- if (requireNamespace('jmvcore')) R6::R6Class(
.run = function() {

# Initial Message ----
if ( is.null(self$options$dep) ) {
if ( length(self$options$dep) <= 1 ) {

# TODO ----

todo <- glue::glue(
"<br>Welcome to ClinicoPath
"<br>Welcome to ClinicoPath
<br><br>
This tool will help you generate Bar Charts.
<br><br>
This function uses ggplot2 and ggstatsplot packages. See documentations <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/ggbarstats.html' target='_blank'>here</a> and <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggbarstats.html' target='_blank'>here</a>.
This function uses ggplot2 and ggstatsplot packages. See documentations <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/ggcorrmat.html' target='_blank'>ggcorrmat</a> and <a href = 'https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggcorrmat.html' target='_blank'>grouped_ggcorrmat</a>.
<br>
Please cite jamovi and the packages as given below.
<br><hr>"
Expand Down Expand Up @@ -54,7 +54,7 @@ jjcorrmatClass <- if (requireNamespace('jmvcore')) R6::R6Class(
# the plot function ----
# Error messages ----

if ( is.null(self$options$dep) )
if ( length(self$options$dep) <= 1 )
return()

if (nrow(self$data) == 0)
Expand All @@ -74,6 +74,7 @@ jjcorrmatClass <- if (requireNamespace('jmvcore')) R6::R6Class(
if (excl) {mydata <- jmvcore::naOmit(mydata)}


# define main arguments ----

myvars <- jmvcore::constructFormula(terms = self$options$dep)

Expand Down Expand Up @@ -123,97 +124,90 @@ jjcorrmatClass <- if (requireNamespace('jmvcore')) R6::R6Class(

}

#
# ,
#
# .plot2 = function(image, ...) {
# # the plot function ----
# # Error messages ----
#
# if ( is.null(self$options$dep) || is.null(self$options$grvar))
# return()
#
# if (nrow(self$data) == 0)
# stop('Data contains no (complete) rows')
#
#
# # Prepare Data ----
#
# mydata <- self$data
#
#
# # direction, paired ----
#
# direction <- self$options$direction
#
# if (direction == "repeated") {
#
# paired <- TRUE
#
# } else if (direction == "independent") {
#
# paired <- FALSE
#
# }
#
# # Exclude NA ----
#
# excl <- self$options$excl
#
# if (excl) {mydata <- jmvcore::naOmit(mydata)}
#
#
#
# dep <- self$options$dep
#
#
#
# dep <- jmvcore::composeTerm(components = dep)
#
#
#
#
#
#
# # grouped_ggcorrmat
# # https://indrajeetpatil.github.io/ggstatsplot/reference/grouped_ggcorrmat.html
#
#
#
# if ( !is.null(self$options$grvar) ) {
# grvar <- self$options$grvar
#
# plot2 <- ggstatsplot::grouped_ggcorrmat(
# data,
# cor.vars = NULL,
# cor.vars.names = NULL,
# grouping.var,
# title.prefix = NULL,
# output = "plot",
# ...,
# plotgrid.args = list(),
# title.text = NULL,
# title.args = list(size = 16, fontface = "bold"),
# caption.text = NULL,
# caption.args = list(size = 10),
# sub.text = NULL,
# sub.args = list(size = 12)
# )
#
#
# }
#
# # Print Plot ----
#
# print(plot2)
# TRUE
#
# }
#

,

.plot2 = function(image, ...) {
# the plot function ----
# Error messages ----

if ( is.null(self$options$dep) || is.null(self$options$grvar))
return()

if (nrow(self$data) == 0)
stop('Data contains no (complete) rows')


# Prepare Data ----

mydata <- self$data


# direction, paired ----

direction <- self$options$direction

if (direction == "repeated") {

paired <- TRUE

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

paired <- FALSE

}

# Exclude NA ----

excl <- self$options$excl

if (excl) {mydata <- jmvcore::naOmit(mydata)}


# define main arguments ----

myvars <- jmvcore::constructFormula(terms = self$options$dep)

myvars <- jmvcore::decomposeFormula(formula = myvars)

myvars <- unlist(myvars)


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



if ( !is.null(self$options$grvar) ) {

grvar <- self$options$grvar

plot2 <- ggstatsplot::grouped_ggcorrmat(
data = mydata,
cor.vars = myvars,
cor.vars.names = NULL,
grouping.var = !!grvar,
title.prefix = NULL,
output = "plot",
plotgrid.args = list(),
title.text = NULL,
title.args = list(size = 16, fontface = "bold"),
caption.text = NULL,
caption.args = list(size = 10),
sub.text = NULL,
sub.args = list(size = 12)
)


}

# Print Plot ----

print(plot2)
TRUE

}

)
)

Expand Down
21 changes: 18 additions & 3 deletions R/jjcorrmat.h.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ jjcorrmatResults <- if (requireNamespace('jmvcore')) R6::R6Class(
inherit = jmvcore::Group,
active = list(
todo = function() private$.items[["todo"]],
plot2 = function() private$.items[["plot2"]],
plot = function() private$.items[["plot"]]),
private = list(),
public=list(
initialize=function(options) {
super$initialize(
options=options,
name="",
title="jjcorrmat",
title="Correlation Matrix",
refs=list(
"ggplot2",
"ggstatsplot"))
Expand All @@ -84,10 +85,23 @@ jjcorrmatResults <- if (requireNamespace('jmvcore')) R6::R6Class(
"dep",
"grvar",
"direction")))
self$add(jmvcore::Image$new(
options=options,
name="plot2",
title="Chart",
width=800,
height=600,
renderFun=".plot2",
requiresData=TRUE,
clearWith=list(
"dep",
"grvar",
"direction"),
visible="(grvar)"))
self$add(jmvcore::Image$new(
options=options,
name="plot",
title="`Bar Chart ${group} - {dep}`",
title="Chart",
width=800,
height=600,
renderFun=".plot",
Expand Down Expand Up @@ -117,7 +131,7 @@ jjcorrmatBase <- if (requireNamespace('jmvcore')) R6::R6Class(
requiresMissings = FALSE)
}))

#' jjcorrmat
#' Correlation Matrix
#'
#' 'Wrapper Function for ggstatsplot::ggbarstats and
#' ggstatsplot::grouped_ggbarstats to generate Bar Charts.'
Expand All @@ -135,6 +149,7 @@ jjcorrmatBase <- 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$plot2} \tab \tab \tab \tab \tab an image \cr
#' \code{results$plot} \tab \tab \tab \tab \tab an image \cr
#' }
#'
Expand Down
Loading

0 comments on commit 94e1eaf

Please sign in to comment.