Betweenstats

Authors

[Editor] Hu Zheng;

[Contributors]

Setup

  • System Requirements: Cross-platform (Linux/MacOS/Windows)

  • Programming language: R

  • Dependent packages: ggstatsplot; ggplot2; cowplot

# Install packages
if (!requireNamespace("ggstatsplot", quietly = TRUE)) {
  install.packages("ggstatsplot")
}
if (!requireNamespace("ggplot2", quietly = TRUE)) {
  install.packages("ggplot2")
}
if (!requireNamespace("cowplot", quietly = TRUE)) {
  install.packages("cowplot")
}

# Load packages
library(ggstatsplot)
library(ggplot2)
library(cowplot)

Data Preparation

# Load data
data <- read.delim("files/Hiplot/064-ggbetweenstats-data.txt", header = T)

# Convert data structure
axis <- c("mpaa", "length", "genre")
data[, axis[1]] <- factor(data[, axis[1]], levels = unique(data[, axis[1]]))
data[, axis[3]] <- factor(data[, axis[3]], levels = unique(data[, axis[3]]))

# View data
head(data)
                                                                 title year
1                       Lord of the Rings: The Return of the King, The 2003
2                   Lord of the Rings: The Fellowship of the Ring, The 2001
3                               Lord of the Rings: The Two Towers, The 2002
4                                                            Star Wars 1977
5                       Star Wars: Episode V - The Empire Strikes Back 1980
6 Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb 1964
  length budget rating  votes  mpaa  genre
1    251   94.0    9.0 103631 PG-13 Action
2    208   93.0    8.8 157608 PG-13 Action
3    223   94.0    8.8 114797 PG-13 Action
4    125   11.0    8.8 134640    PG Action
5    129   18.0    8.8 103706    PG Action
6     93    1.8    8.7  63471    PG Comedy

Visualization

# Betweenstats
g <- unique(data[,axis[3]])
plist <- list()
for (i in 1:length(g)) {
  fil <- data[,axis[3]] == g[i]
  plist[[i]] <- ggbetweenstats(
    data = data[fil,], x = mpaa, y = length,
    title= paste('', axis[3], g[i], sep = ':'),
    p.adjust.method = "holm",
    plot.type = "boxviolin",
    pairwise.comparisons = T,
    pairwise.display = "significant",
    effsize.type = "unbiased",
    notch = T,
    type = "parametric",
    plotgrid.args = list(ncol = 2)) +
    scale_color_manual(values = c("#00468BFF","#ED0000FF","#42B540FF"))
}
Error in validObject(.Object) : 
  invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
Error in validObject(.Object) : 
  invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
Error in validObject(.Object) : 
  invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
Error in validObject(.Object) : 
  invalid class "ddenseModelMatrix" object: superclass "xMatrix" not defined in the environment of the object's class
p <- plot_grid(plotlist = plist, ncol = 2)

p
FigureΒ 1: Betweenstats