作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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 的变化在每个组中都显着,我尝试使用重复方差分析来测试。例如在 A 组、B 组、C 组 1、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
关于r - 如何正确使用 ggstatsplot 包中的 grouped_ggwithinstats() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74762091/
我正在尝试使用 grouped_ggwithinstats()来自 ggstatsplot 的函数包裹: 我有这个数据集: df You can cite this package as: #>
我是一名优秀的程序员,十分优秀!