本期教程原文:使用最简单方法添加显著性ggsignif包
本期教程
获得本期教程代码和数据,在后台回复关键词:20240605
小杜的生信笔记,自2021年11月开始做的知识分享,主要内容是R语言绘图教程、转录组上游分析、转录组下游分析等内容。凡是在社群同学,可免费获得自2021年11月份至今全部教程,教程配备事例数据和相关代码,我们会持续更新中。
往期教程部分内容
代码
##
library(ggplot2)
library(tidyverse)
library(ggpubr)
library(dplyr)
library(multcompView)
library(ggbreak)
library(data.table)
数据
#'@数据
set.seed(123) # 设置随机种子以确保结果可重复
samples <- c("CK", "80-1", "4-7", "4-14", "4-60", "20-7", "20-14", "20-60")
mean_values <- c(3, 2.5, 4, 2, 1.5, 4.5, 2.8, 3.5)
data_matrix <- data.frame(
sample = rep(samples, each = 6),
value = unlist(lapply(mean_values, function(mu) rnorm(6, mean = mu, sd = 0.3)))
)
若是宽数据,转换长数据即可,可看我们的教程:https://mp.weixin.qq.com/s/i8x0WTcXTrVgD7NGBE3hcA
绘图
##'@固定因子
data_matrix$sample <- factor(data_matrix$sample, levels = c("CK","80-1","4-7","20-7","4-14","20-14","4-60","20-60"))
ggplot(data_matrix, aes(x = sample, y = value, fill = sample)) +
stat_summary(fun.data = mean_sd, geom = "errorbar", width = 0.15, size = 1) +
geom_bar(color = "black", stat = "summary", fun = mean, position = "dodge", size = 0.5) +
##'@Y轴从0开始
scale_y_continuous(expand = c(0,0))+
#theme_classic()+
#theme_test(base_size = 14)+
theme_bw(base_size = 14)+
## 差异比较组合
stat_compare_means(comparisons = list(c("CK","80-1"),
c("CK","4-7"),
c("CK","4-14"),
c("CK","4-60"),
c("CK","20-7"),
c("CK","20-14"),
c("CK","20-60")),
tip.length = 0.02,
method = "wilcox.test", ## t.test, wilcox.test,anova,kruskal.test
label = "p.format" ## p.signif:显示显著性星号,p.format:显示数字
)+
scale_fill_manual(values = c("#1f78b4","#ff7f00","#4daf4a",
"#fb8072", "#8da0cb",
"#bf5b17","#b2df8a","#c8c9c9","#7570b3"))+
labs(x = NULL,y = "Expression level of genes (FPKM)")+
theme(#axis.line = element_line(size = 1), ## 粗细
text=element_text(#family = "sans",
colour ="black",size = 10),
axis.text.x = element_text(color = "black", size = 10),
axis.text.y = element_text(color = "black",size = 10),
axis.ticks = element_line(colour = "black"),
strip.text = element_text(color = "black",size = 10),
axis.title = element_text(color = "black",size = 12), ##坐标轴字体大小
legend.position = "none",
strip.background = element_blank()
)
本期教程原文:使用最简单方法添加显著性ggsignif包
获得本期教程代码和数据,在后台回复关键词:20240605
若我们的教程对你有所帮助,请
点赞+收藏+转发
,这是对我们最大的支持。
往期部分文章
1. 最全WGCNA教程(替换数据即可出全部结果与图形)
2. 精美图形绘制教程
3. 转录组分析教程
4. 转录组下游分析
小杜的生信筆記 ,主要发表或收录生物信息学教程,以及基于R分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!!