这是我正在制作的情节:
我使用 ggplot 根据两个参数(
treatment
和 crown.layer
)绘制了我的数据,现在的目标是添加 p 值,以显示这些参数组内和组间的显着差异。因此,我想确定全局方差分析 p 值,并执行事后检验来成对比较所有组。
我应用了此链接中提供的代码。
这是我的代码: 我使用两个不同的数据集来运行测试和绘图,因为测试不适用于聚合数据集。
stat.test <- rel_data %>%
group_by(treatment) %>%
t_test(rel_fruit ~ crown.layer) %>%
adjust_pvalue(method = "bonferroni") %>%
add_significance("p.adj")%>%
add_xy_position(x = "treatment", dodge = 0.8)
stat.test2 <- rel_data %>%
t_test(rel_fruit ~ treatment, p.adjust.method = "bonferroni")%>%
add_xy_position(x = "treatment")
ggplot(grouped_data, aes(x=treatment, y=mean_fruit_b, fill=crown.layer)) +
geom_boxplot()+
geom_jitter()+
labs( x = "treatment", y = "mean fruit to closed bud ratio [%]",title = "Fruit Development")+
theme_light()+
stat_pvalue_manual(stat.test, label = "p", tip.length = 0)+
stat_pvalue_manual(stat.test2, label = "p", tip.length = 0.02,step.increase = 0.05) +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))+
scale_fill_manual (values = c("lower"="#b0e0e6","middle"="lightpink","upper"="lightgoldenrod1"))
不知何故,我收到以下错误消息...
Error:
! Problem while computing aesthetics.
ℹ Error occurred in the 3rd layer.
Caused by error:
! Objekt 'crown.layer' nicht gefunden
Backtrace:
1. base (local) `<fn>`(x)
2. ggplot2:::print.ggplot(x)
4. ggplot2:::ggplot_build.ggplot(x)
5. ggplot2:::by_layer(...)
12. ggplot2 (local) f(l = layers[[i]], d = data[[i]])
13. l$compute_aesthetics(d, plot)
14. ggplot2 (local) compute_aesthetics(..., self = self)
15. base::lapply(aesthetics, eval_tidy, data = data, env = env)
16. rlang (local) FUN(X[[i]], ...)
crown.layer
中使用的
ggplot(grouped_data, aes(x=treatment, y=mean_fruit_b, fill=crown.layer))
变量似乎不在您的 grouped_data
数据集中
所以你应该添加它:
grouped_data$crown.layer <- rel_data$crown.layer
(如果它在
rel_data
数据集中)
这里有一些附加信息。
stat.test的输出:
treatment .y. group1 group2 n1 n2 statistic df p p.adj p.adj.signif y.position
<chr> <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <chr> <dbl>
1 bag rel_fru… lower middle 62 12 -1.28 19.3 0.214 1 ns 0.994
2 bag rel_fru… lower upper 62 84 -3.70 117. 0.00033 0.00198 ** 1.14
3 bag rel_fru… middle upper 12 84 -2.21 51.6 0.032 0.192 ns 1.28
4 open-air rel_fru… lower middle 68 12 -1.26 11.9 0.232 1 ns 1.09
5 open-air rel_fru… lower upper 68 83 -2.29 141. 0.024 0.144 ns 1.24
6 open-air rel_fru… middle upper 12 83 0.456 12.9 0.656 1 ns 1.38
stat.test2 的输出:
.y. group1 group2 n1 n2 statistic df p y.position groups xmin xmax
<chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <dbl> <named list> <dbl> <dbl>
1 rel_fruit bag open-air 158 163 0.579 318. 0.563 1.01 <chr [2]> 1 2
提前感谢您的帮助!