# Example 1
#::::::::::::::::::::::::::::::::::::::::::
library(reshape)
library(report)
id<-c(1:15)
before <-c(2.3,2.5,2.1,1.4,1.6,3.3,1.7,2.7,1.2,2.1,1.6,2.3,1.4,3.1,1.5)
after <-c(2.8,3.0,2.7,2.2,2.1,3.7,2.3,3.3,2.1,2.6,2.8,2.9,1.9,3.8,2.7)
#2.3,2.5,2.1,1.4,1.6,3.5,1.7,2.7,1.2,2.1,1.6,2.3,1.4,2.7,3.1,1.5
d <- data.frame(id=id,before = before, after= after)
library(ggpubr)
## Loading required package: ggplot2
ggpaired(d, cond1 = "before", cond2 = "after",
         fill = "condition",palette = "jco")

cor.test(d$before, d$after) %>%
  report()
## Registered S3 methods overwritten by 'parameters':
##   method                           from      
##   as.double.parameters_kurtosis    datawizard
##   as.double.parameters_skewness    datawizard
##   as.double.parameters_smoothness  datawizard
##   as.numeric.parameters_kurtosis   datawizard
##   as.numeric.parameters_skewness   datawizard
##   as.numeric.parameters_smoothness datawizard
##   print.parameters_distribution    datawizard
##   print.parameters_kurtosis        datawizard
##   print.parameters_skewness        datawizard
##   summary.parameters_kurtosis      datawizard
##   summary.parameters_skewness      datawizard
## Effect sizes were labelled following Funder's (2019) recommendations.
## 
## The Pearson's product-moment correlation between d$before and d$after is positive, statistically significant, and very large (r = 0.92, 95% CI [0.78, 0.97], t(13) = 8.67, p < .001)
socialwork<-melt(d,id.vars=c("id"))
library(ggstatsplot)
## You can cite this package as:
##      Patil, I. (2021). Visualizations with statistical details: The 'ggstatsplot' approach.
##      Journal of Open Source Software, 6(61), 3167, doi:10.21105/joss.03167
library(tidyverse)
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## Found more than one class "atomicVector" in cache; using the first, from namespace 'Matrix'
## Also defined by 'Rmpfr'
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## v purrr   0.3.4
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x tidyr::expand() masks reshape::expand()
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## x dplyr::rename() masks reshape::rename()
library(gtsummary)
socialwork%<>% 
  rename(group = variable)
#remotes::install_github("ashenoy-cmbi/grafify@*release")
socialwork %>%
  select(group, value) %>%
  tbl_summary(
    by = group, # split table by group
    missing = "no" ,# don't list missing data separately ,
    statistic = all_continuous() ~ c(
    "{median}/{mean}({p25}, {p75})")
  ) %>%
  add_n() %>% # add column with total number of non-missing observations
  add_p(test = list(all_continuous() ~ "t.test"))%>% # test for a difference between groups
  modify_header(label = "**Variable**") %>% # update the column header
  bold_labels() 
Variable N before, N = 151 after, N = 151 p-value2
value 30 2.10/2.05(1.55, 2.40) 2.70/2.73(2.25, 2.95) 0.005

1 Median/Mean(IQR)

2 Welch Two Sample t-test

library(grafify)
## Loading required package: emmeans
## Loading required package: lmerTest
## Loading required package: lme4
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## The following object is masked from 'package:reshape':
## 
##     expand
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
plot_befafter_colours(data = socialwork,
                      xcol = group,
                      ycol = value,
                      groups = id,
                      symsize = 5,
                      ColPal = "light",
                      ColRev = T)+
  labs(title = "Comparison")

socialwork %>%
  ggbetweenstats(
    x = group,
    y = value,
    type = "parametric",
    pairwise.comparisons = TRUE, 
    pairwise.display = "s",
    #results.subtitle = FALSE,
    messages = FALSE,
    var.equal = FALSE,
    bf.messages = FALSE
  )