Skip to contents

Wrapper Function for ggstatsplot::ggscatterstats and ggstatsplot::grouped_ggscatterstats to generate scatter plots with correlation analysis and optional marginal distributions.

Usage

jjscatterstats(
  data,
  dep,
  group,
  grvar = NULL,
  typestatistics = "parametric",
  mytitle = "",
  xtitle = "",
  ytitle = "",
  originaltheme = FALSE,
  resultssubtitle = FALSE,
  conflevel = 0.95,
  bfmessage = FALSE,
  k = 2,
  marginal = FALSE,
  xsidefill = "#009E73",
  ysidefill = "#D55E00",
  pointsize = 3,
  pointalpha = 0.4,
  smoothlinesize = 1.5,
  smoothlinecolor = "blue",
  plotwidth = 600,
  plotheight = 450
)

Arguments

data

The data as a data frame.

dep

First continuous variable for correlation analysis (e.g., biomarker levels, age, tumor size). This will appear on the horizontal axis. Use numeric variables like lab values, measurements, or scores.

group

Second continuous variable for correlation analysis (e.g., expression levels, treatment response, survival time). This will appear on the vertical axis. Use numeric variables that you want to correlate with the x-axis variable.

grvar

Optional categorical variable to create separate correlation plots for each group (e.g., by treatment group, tumor stage, or gender). Creates multiple panels for comparison.

typestatistics

Choose based on your data distribution. Pearson assumes normality (common for lab values after transformation). Spearman works for any monotonic relationship (tumor grades, symptom scores). Robust methods handle outlying patients. Bayesian analysis quantifies evidence strength for clinical decision-making.

mytitle

.

xtitle

.

ytitle

.

originaltheme

.

resultssubtitle

.

conflevel

Confidence level for confidence intervals (between 0 and 1).

bfmessage

Whether to display Bayes Factor in the subtitle when using Bayesian analysis.

k

Number of decimal places for displaying statistics in the subtitle.

marginal

Whether to display marginal histogram plots on the axes using ggside.

xsidefill

Fill color for x-axis marginal histogram.

ysidefill

Fill color for y-axis marginal histogram.

pointsize

Size of the scatter plot points.

pointalpha

Transparency level for scatter plot points.

smoothlinesize

Width of the regression/smooth line.

smoothlinecolor

Color of the regression/smooth line.

plotwidth

Width of the plot in pixels. Default is 600.

plotheight

Height of the plot in pixels. Default is 450.

Value

A results object containing:

results$todoa html
results$plot2an image
results$plotan image

Examples

# \donttest{
# Load test data
data("mtcars")

# Basic scatter plot with correlation
jjscatterstats(
  data = mtcars,
  dep = "mpg",       # x-axis
  group = "hp",      # y-axis
  typestatistics = "parametric",
  conflevel = 0.95,
  k = 2
)
#> 
#>  SCATTER PLOT
#> 
#>  You have selected to use a scatter plot with correlation analysis.


# Scatter plot with marginal histograms
jjscatterstats(
  data = mtcars,
  dep = "mpg",
  group = "hp",
  marginal = TRUE,
  xsidefill = "#009E73",
  ysidefill = "#D55E00",
  pointsize = 4,
  pointalpha = 0.6,
  smoothlinesize = 2,
  smoothlinecolor = "red"
)
#> 
#>  SCATTER PLOT
#> 
#>  You have selected to use a scatter plot with correlation analysis.


# Grouped scatter plot by number of cylinders
jjscatterstats(
  data = mtcars,
  dep = "mpg",
  group = "hp",
  grvar = "cyl",
  typestatistics = "nonparametric",
  bfmessage = FALSE,
  resultssubtitle = TRUE
)
#> 
#>  SCATTER PLOT
#> 
#>  You have selected to use a scatter plot with correlation analysis.
#> Error in terms.formula(formula): invalid model formula in ExtractVars
# }