[英]How to remove dots ggwithinstats in the package ggstatsplot
[英]How to use grouped_ggwithinstats() function from ggstatsplot package correctly
我正在嘗試使用 ggstatsplot package 中的grouped_ggwithinstats()
ggstatsplot
:
我有這個數據集:
df <- structure(list(time = c(0L, 1L, 2L, 3L, 0L, 1L, 2L, 3L, 0L, 1L,
2L, 3L, 0L, 1L, 2L, 3L), group1 = c("A", "A", "A", "A", "B",
"B", "B", "B", "C 1", "C 1", "C 1", "C 1", "C 2", "C 2", "C 2",
"C 2"), group2 = c("Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z",
"Z", "Z", "Z", "Z", "Z", "Z", "Z"), value = c(100L, 60L, 30L,
32L, 100L, 2L, 3L, 1L, 100L, 17L, 17L, 8L, 100L, 35L, 36L, 22L
)), class = "data.frame", row.names = c("1", "2", "3", "4", "5",
"6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"))
time group1 group2 value
1 0 A Z 100
2 1 A Z 60
3 2 A Z 30
4 3 A Z 32
5 0 B Z 100
6 1 B Z 2
7 2 B Z 3
8 3 B Z 1
9 0 C 1 Z 100
10 1 C 1 Z 17
11 2 C 1 Z 17
12 3 C 1 Z 8
13 0 C 2 Z 100
14 1 C 2 Z 35
15 2 C 2 Z 36
16 3 C 2 Z 22
使用此代碼:
library(ggstatsplot)
ggbetweenstats(
data = df,
x = time,
y = value,
type = "nonparametric",
plot.type = "box",
centrality.plotting = FALSE
)
我現在想按group1
分組並在每個組中標記點: 所以當我這樣做時:
grouped_ggbetweenstats(
data = df,
x = time,
y = value,
grouping.var = group1,
type = "nonparametric",
plot.type = "box",
centrality.plotting = FALSE
)
我不明白ggwithinstats
與ggbetweenstats
之間關於grouped_ggbetweenstats()
和grouped_ggwithinstats()
的區別,后者給出錯誤:
Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 0, 1
我嘗試測試的是使用重復方差分析,如果時間點 0、1、2、3 的變化在每個組中都很顯着。 例如在GroupA,Group B,Group C 1,Group C 2。
您正在正確使用grouped_ggwithinstats()
,但是您收到所有這些警告是因為沒有足夠的數據來運行假設檢驗和估計。
每組每個條件都有一個數據,因此無法運行統計測試,因此字幕和標題是空的。
library(dplyr, warn.conflicts = FALSE)
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
df <- tibble(time = c(
0L, 1L, 2L, 3L, 0L, 1L, 2L, 3L, 0L, 1L,
2L, 3L, 0L, 1L, 2L, 3L
), group1 = c(
"A", "A", "A", "A", "B",
"B", "B", "B", "C 1", "C 1", "C 1", "C 1", "C 2", "C 2", "C 2",
"C 2"
), group2 = c(
"Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z",
"Z", "Z", "Z", "Z", "Z", "Z", "Z"
), value = c(
100L, 60L, 30L,
32L, 100L, 2L, 3L, 1L, 100L, 17L, 17L, 8L, 100L, 35L, 36L, 22L
))
df %>%
group_by(group1, time) %>%
count()
#> # A tibble: 16 × 3
#> # Groups: group1, time [16]
#> group1 time n
#> <chr> <int> <int>
#> 1 A 0 1
#> 2 A 1 1
#> 3 A 2 1
#> 4 A 3 1
#> 5 B 0 1
#> 6 B 1 1
#> 7 B 2 1
#> 8 B 3 1
#> 9 C 1 0 1
#> 10 C 1 1 1
#> 11 C 1 2 1
#> 12 C 1 3 1
#> 13 C 2 0 1
#> 14 C 2 1 1
#> 15 C 2 2 1
#> 16 C 2 3 1
grouped_ggwithinstats(
data = df,
x = time,
y = value,
grouping.var = group1,
type = "nonparametric",
pairwise.comparisons = FALSE,
centrality.plotting = FALSE
)
#> Warning: Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Warning in max(data$density): no non-missing arguments to max; returning -Inf
#> Warning: Computation failed in `stat_ydensity()`
#> Caused by error in `$<-.data.frame`:
#> ! replacement has 1 row, data has 0
#> Warning: Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Warning in max(data$density): no non-missing arguments to max; returning -Inf
#> Warning: Computation failed in `stat_ydensity()`
#> Caused by error in `$<-.data.frame`:
#> ! replacement has 1 row, data has 0
#> Warning: Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Warning in max(data$density): no non-missing arguments to max; returning -Inf
#> Warning: Computation failed in `stat_ydensity()`
#> Caused by error in `$<-.data.frame`:
#> ! replacement has 1 row, data has 0
#> Warning: Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Groups with fewer than two data points have been dropped.
#> Warning in max(data$density): no non-missing arguments to max; returning -Inf
#> Warning: Computation failed in `stat_ydensity()`
#> Caused by error in `$<-.data.frame`:
#> ! replacement has 1 row, data has 0
創建於 2022-12-12,使用reprex v2.0.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.