library(openxlsx)
library(dplyr)
library(car)
library(ggplot2)
library(ggpubr)
library(ggthemes)
# 读入数据
df <- read.xlsx("data/qpcr.xlsx",sheet = 1)
df

head(df)
str(df)
# 因子化
df$group <- factor(df$group, levels = c("CTRL", "A"))
# 验证正态性
df %>%
group_by(group) %>%
summarise(p_value = shapiro.test(GENE1)$p.value) %>%
ungroup()
# 检验方差齐性
levene_test <- leveneTest(GENE1 ~ group, data = df)
levene_test
# 如果 p > 0.05,使用 t-test
# 如果 p <= 0.05,使用 wilcoxon
# t-test
t_test <- t.test(GENE1 ~ group, data = df)
t_test
# # wilcoxon
# wilcox_test <- wilcox.test(GENE1 ~ group, data = df)
# wilcox_test
# ggpubr中的t检验
stat.test <- compare_means(GENE1 ~ group, data = df, method = "t.test")
# 结果一致
# 配色自定义
colors <- c("#5982B5", "#36578D")
# 绘制柱状图并添加显著性分析
ggplot(df, aes(x = group, y = GENE1, fill = group)) +
stat_summary(fun = mean, geom = "bar", position = position_dodge(0.9), alpha = 0.6) +
geom_point(position = position_dodge(0.9),
aes(color = group), size =1, alpha = 0.6) +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar",
width = 0.2, position = position_dodge(0.9)) + # 绘制误差线
stat_compare_means(comparisons = list(c("CTRL", "A")),
method = "t.test", label = "p.signif",
size = 3, label.y = c(1.2)) + # 添加星号
labs(x = "Treatment", y = "Relative Expression") +
scale_fill_manual(values = colors) + # 填充颜色
scale_color_manual(values = colors) + # 点的颜色
theme_few()
ggsave("output/qpcr_GENE1_group1.png", width = 5, height = 8, dpi = 300) # 保存图片
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删