|
1 | 1 | --- |
2 | | -title: "Continuous Variable Comparisons" |
| 2 | +title: "Categorical Plot Functions" |
3 | 3 | output: rmarkdown::html_vignette |
4 | 4 | vignette: > |
5 | | - %\VignetteIndexEntry{Continuous Variable Comparisons} |
| 5 | + %\VignetteIndexEntry{Categorical Plot Functions} |
6 | 6 | %\VignetteEngine{rmarkdown} |
7 | 7 | %\VignetteEncoding{UTF-8} |
8 | 8 | --- |
9 | 9 |
|
10 | 10 | ```{r setup, include=FALSE} |
11 | 11 | knitr::opts_chunk$set(comment = "#>", collapse = TRUE) |
| 12 | +library(dplyr) |
12 | 13 | library(jjstatsplot) |
| 14 | +library(ggstatsplot) |
13 | 15 | data(mtcars) |
| 16 | +
|
| 17 | +# Convert relevant variables to factors for categorical analysis |
| 18 | +mtcars$cyl <- as.factor(mtcars$cyl) |
| 19 | +mtcars$am <- as.factor(mtcars$am) |
| 20 | +mtcars$vs <- as.factor(mtcars$vs) |
14 | 21 | ``` |
15 | 22 |
|
16 | | -This article focuses on functions that compare continuous variables. |
| 23 | +This vignette demonstrates the categorical plot functions available in the jjstatsplot package. These functions are designed to work within the jamovi interface, but we can demonstrate their underlying functionality using the ggstatsplot functions they wrap. |
| 24 | + |
| 25 | +## Bar charts with `jjbarstats()` |
| 26 | + |
| 27 | +The `jjbarstats()` function creates bar charts and performs chi-squared tests to compare categorical variables. It wraps `ggstatsplot::ggbarstats()`. |
| 28 | + |
| 29 | +```{r, fig.width=7, fig.height=5} |
| 30 | +# Underlying function that jjbarstats() wraps |
| 31 | +ggstatsplot::ggbarstats( |
| 32 | + data = mtcars, |
| 33 | + x = cyl, |
| 34 | + y = am, |
| 35 | + title = "Cylinders by Transmission Type" |
| 36 | +) |
| 37 | +``` |
17 | 38 |
|
18 | | -## Comparing groups with `jjbetweenstats()` |
| 39 | +## Pie charts with `jjpiestats()` |
19 | 40 |
|
20 | | -`jjbetweenstats()` combines box and violin plots to compare a continuous |
21 | | -response across groups. Statistical tests such as ANOVA or their |
22 | | -non-parametric equivalents are performed automatically depending on the |
23 | | -`typestatistics` argument. |
| 41 | +The `jjpiestats()` function creates pie charts for categorical data visualization. It wraps `ggstatsplot::ggpiestats()`. |
24 | 42 |
|
25 | | -```{r} |
26 | | -jjbetweenstats(data = mtcars, dep = mpg, group = cyl) |
| 43 | +```{r, fig.width=7, fig.height=5} |
| 44 | +# Underlying function that jjpiestats() wraps |
| 45 | +ggstatsplot::ggpiestats( |
| 46 | + data = mtcars, |
| 47 | + x = cyl, |
| 48 | + y = am, |
| 49 | + title = "Distribution of Cylinders by Transmission" |
| 50 | +) |
27 | 51 | ``` |
28 | 52 |
|
29 | | -## Repeated measures with `jjwithinstats()` |
| 53 | +## Dot charts with `jjdotplotstats()` |
30 | 54 |
|
31 | | -For paired or repeated observations, `jjwithinstats()` displays the |
32 | | -measurements for each condition alongside the results of a paired test. |
33 | | -Below we compare miles-per-gallon recorded in two hypothetical |
34 | | -conditions represented by `mpg` and `hp` just for demonstration. |
| 55 | +The `jjdotplotstats()` function shows group comparisons using dot plots. It wraps `ggstatsplot::ggdotplotstats()`. |
35 | 56 |
|
36 | | -```{r} |
37 | | -jjwithinstats(data = mtcars, dep1 = mpg, dep2 = hp) |
| 57 | +```{r, fig.width=7, fig.height=5} |
| 58 | +# Underlying function that jjdotplotstats() wraps |
| 59 | +ggstatsplot::ggdotplotstats( |
| 60 | + data = mtcars, |
| 61 | + x = hp, |
| 62 | + y = vs, |
| 63 | + title = "Horsepower by Engine Configuration" |
| 64 | +) |
38 | 65 | ``` |
39 | 66 |
|
40 | | -## Histograms with `jjhistostats()` |
| 67 | +## Within-group comparisons with `jjwithinstats()` |
41 | 68 |
|
42 | | -`jjhistostats()` produces histograms and overlays the results of a test |
43 | | -for normality. The example below shows the distribution of engine |
44 | | -horsepower. |
| 69 | +The `jjwithinstats()` function compares repeated measurements within groups. It wraps `ggstatsplot::ggwithinstats()`. |
45 | 70 |
|
46 | | -```{r} |
47 | | -jjhistostats(data = mtcars, dep = hp) |
| 71 | +```{r, fig.width=8, fig.height=6} |
| 72 | +# Create long format data for within-group comparison |
| 73 | +library(tidyr) |
| 74 | +mtcars_long <- mtcars %>% |
| 75 | + select(mpg, hp, wt, qsec) %>% |
| 76 | + mutate(id = row_number()) %>% |
| 77 | + pivot_longer(cols = c(mpg, hp, wt, qsec), |
| 78 | + names_to = "measure", |
| 79 | + values_to = "value") %>% |
| 80 | + # Standardize values for comparison |
| 81 | + group_by(measure) %>% |
| 82 | + mutate(value = scale(value)[,1]) %>% |
| 83 | + ungroup() |
| 84 | +
|
| 85 | +# Underlying function that jjwithinstats() wraps |
| 86 | +ggstatsplot::ggwithinstats( |
| 87 | + data = mtcars_long, |
| 88 | + x = measure, |
| 89 | + y = value, |
| 90 | + paired = TRUE, |
| 91 | + id = id, |
| 92 | + title = "Comparison of Standardized Car Measurements" |
| 93 | +) |
48 | 94 | ``` |
49 | 95 |
|
| 96 | +## Usage in jamovi |
| 97 | + |
| 98 | +These functions are designed to be used through the jamovi graphical interface, where they provide: |
| 99 | + |
| 100 | +- Interactive parameter selection |
| 101 | +- Automatic data type handling |
| 102 | +- Integrated results display |
| 103 | +- Export capabilities |
| 104 | + |
| 105 | +To use these functions in jamovi: |
| 106 | + |
| 107 | +1. Install the jjstatsplot module |
| 108 | +2. Load your data |
| 109 | +3. Navigate to the JJStatsPlot menu |
| 110 | +4. Select the appropriate plot type |
| 111 | +5. Configure variables and options through the interface |
50 | 112 |
|
| 113 | +The jamovi interface handles parameter validation, data preprocessing, and result presentation automatically. |
0 commit comments