如何从数据中选择两组进行t检验和条形图?我有几个组/衬底(即O1、O2、O3、S_O4、S_O5等)组成的数据,我需要使用特定的两个组/衬底(例如O1和S_O5)绘制条形图,然后运行t测试。我需要帮助。请检查附件中Excel数据的链接,好吗?
library(ggpubr)
library(rstatix)
library(xlsx)
library(patchwork)
df<-read.xlsx("umar_02.xlsx", header = T, 1)
# Statistical test
######## Figure 1 ########
stat.test <- df %>%
t_test(Moisture_content ~ substrate) %>%
add_significance()
stat.test
# Box plots with p-values
bxp1 <- ggboxplot(df, x = "substrate", y = "Moisture_content", fill = "substrate",
palette = c("#00AFBB", "#E7B800"), width = 0.35)
stat.test <- stat.test %>% add_xy_position(x = "substrate")
bxp1 +
stat_pvalue_manual(stat.test, label = "p = {p}") +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))+
theme(
aspect.ratio = 3
)Excel数据:enter link description here
发布于 2021-08-25 18:21:51
df <- rio::import("https://docs.google.com/spreadsheets/d/1YZQRihyc5aTWehda8Wr24xwm23a87jv7/edit#gid=1007932109")
library(ggpubr)
library(rstatix)
stat.test <- df %>%
filter(Ortamlar %in% c("O1", "S_O5")) %>%
t_test(Moisture_content ~ Ortamlar) %>%
add_significance()
stat.test
stat.test
# # A tibble: 1 x 9
# .y. group1 group2 n1 n2 statistic df p p.signif
# * <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
# 1 Moisture_content O1 S_O5 3 3 -2.20 2.50 0.132 ns
# Box plots with p-values
bxp1 <- df %>%
filter(Ortamlar %in% c("O1", "S_O5")) %>%
ggboxplot( x = "Ortamlar", y = "Moisture_content", fill = "Ortamlar",
palette = c("#00AFBB", "#E7B800"), width = 0.35, xlab = "Substrate")
stat.test %>% add_xy_position(x = "Ortamlar")
stat.test <- stat.test %>% mutate(y.position=5.15)
bxp1 +
stat_pvalue_manual(stat.test, label = "p = {p}") +
scale_y_continuous(expand = expansion(mult = c(0.05, 0.1)))+
theme(
aspect.ratio = 3
)

发布于 2021-08-25 18:16:31
我们可能需要使用%in%进行filter
library(dplyr)
stat.test <- df %>%
filter(Ortamlar %in% c("O1", "S_O5")) %>%
rename(substrate = Ortamlar) %>%
t_test(Moisture_content ~ substrate) %>%
add_significance()-output
stat.test
# A tibble: 1 x 9
.y. group1 group2 n1 n2 statistic df p p.signif
* <chr> <chr> <chr> <int> <int> <dbl> <dbl> <dbl> <chr>
1 Moisture_content O1 S_O5 3 3 -2.20 2.50 0.132 ns https://stackoverflow.com/questions/68927574
复制相似问题