为了避免各位错过最新的推文教程,强烈建议大家将“科研后花园”设置为“星标”!
###安装LorMe包
install.packages("LorMe")
##加载MicrobiomeStat包
library(LorMe) # Lightening One-Code Resolving Microbial Ecology Solution
library(ggplot2) # Create Elegant Data Visualisations Using the Grammar of Graphics
##加载示例数据集
data(testotu) # Load the standard Qiime output feature table
head(testotu) # First column -ID, last column -taxonomic annotation, others - the feature table.
feature_table<- testotu[, -c(1,22)]
tax_anno<- testotu[, c(1,22)]
#创建分组数据
groupinformation <- data.frame(
group = c(rep("a", 10), rep("b", 10)),
factor1 = rnorm(10),
factor2 = rnorm(mean = 100, 10),
subject = factor(c(1:10, 1:10)),
group2 = c(rep("e", 5), rep("f", 5), rep("e", 5), rep("f", 5))
)
###对数据进行封装
test_object <- tax_summary(
groupfile = groupinformation,
inputtable = feature_table,
reads = TRUE,
taxonomytable = tax_anno
)
###对一些默认设置进行配置
my_col=color_scheme("Plan1")
my_order=c("b","a")
my_facet_order=c("e","f")
test_object_plan2 <- object_config(
taxobj = test_object,
treat_location = 1,
rep_location = 4,
facet_location = 5,
subject_location = NULL,
treat_col = my_col,
treat_order = my_order,
facet_order = my_facet_order
)
Taxonomy tidying...
Genarating tables...
Done
Contained elements:
"Groupfile" "Base" "Base_percent" [1]
"Base_taxonomy" "Phylum" "Phylum_percent" [4]
"Phylum_taxonomy" "Genus" "Genus_percent" [7]
"Genus_taxonomy" "parameters" [10]
Warning message:
in 261 rows [4, Expected 7 pieces. Missing pieces filled with `NA`
6, 9, 12, 18, 20, 24, 32, 37, 43, 44, 45, 46, 58, 59, 68, 70, 71,
72, 76, ...].
1)默认基础分析:
Alpha_results<- Alpha_diversity_calculator(taxobj = test_object_plan2,
taxlevel = "Base" #analysis level
)
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.005623099 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.404 )
Treatment_Name N Median Q1 Q3
1 a 10 5.432989 4.492731 5.124226
2 b 10 5.395290 4.973662 5.331129
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 42
n(small)= 10 , n(big)= 10
P_estimate = 0.5707504 ,P_exact = 0.5453497
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.5453497 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.006954524 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.264 )
Treatment_Name N Median Q1 Q3
1 a 10 626.5 336.25 522.4
2 b 10 608.0 516.00 586.9
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 44
n(small)= 10 , n(big)= 10
P_estimate = 0.6774705 ,P_exact = 0.6500246
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.6500246 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.02277682 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.906 )
Treatment_Name N Median Q1 Q3
1 a 10 0.8415442 0.7893959 0.8266527
2 b 10 0.8431299 0.8036199 0.8368023
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 42
n(small)= 10 , n(big)= 10
P_estimate = 0.5707504 ,P_exact = 0.5453497
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.5453497 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.0004472301 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.921 )
Treatment_Name N Median Q1 Q3
1 a 10 0.9909291 0.9793478 0.9865330
2 b 10 0.9903503 0.9799472 0.9865132
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 50
n(small)= 10 , n(big)= 10
P_estimate = 1 ,P_exact = 1
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 1 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.01048326 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.215 )
Treatment_Name N Median Q1 Q3
1 a 10 718.085 414.0291 607.2004
2 b 10 693.228 652.6971 679.5795
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 47
n(small)= 10 , n(big)= 10
P_estimate = 0.8501067 ,P_exact = 0.8205958
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.8205958 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.0108276 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.237 )
Treatment_Name N Median Q1 Q3
1 a 10 712.4917 423.9344 600.2988
2 b 10 671.8403 616.9682 658.7892
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 53
n(small)= 10 , n(big)= 10
P_estimate = 0.8501067 ,P_exact = 0.8205958
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.8205958 ).
Analysis finished
2)在不同分类水平进行Alpha分析(以属水平为例):
Alpha_results2<- Alpha_diversity_calculator(taxobj = test_object_plan2,
taxlevel = "Genus",
prefix = "Genus"
)
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.002079162 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.356 )
Treatment_Name N Median Q1 Q3
1 a 10 4.774252 4.130925 4.541499
2 b 10 4.754462 4.511624 4.690952
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 43
n(small)= 10 , n(big)= 10
P_estimate = 0.6231762 ,P_exact = 0.5967012
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.5967012 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.0127267 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.12 )
Treatment_Name N Median Q1 Q3
1 a 10 285.5 196.75 253.7
2 b 10 281.0 257.50 275.5
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 52
n(small)= 10 , n(big)= 10
P_estimate = 0.9095864 ,P_exact = 0.8796494
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.8796494 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.002801331 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.845 )
Treatment_Name N Median Q1 Q3
1 a 10 0.8443819 0.7964615 0.8238631
2 b 10 0.8451148 0.8118400 0.8349486
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 40
n(small)= 10 , n(big)= 10
P_estimate = 0.4726756 ,P_exact = 0.4496918
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.4496918 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.0003992957 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.955 )
Treatment_Name N Median Q1 Q3
1 a 10 0.9852937 0.9742226 0.9810497
2 b 10 0.9853026 0.9751303 0.9807535
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 49
n(small)= 10 , n(big)= 10
P_estimate = 0.96985 ,P_exact = 0.939743
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.939743 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.02471859 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.161 )
Treatment_Name N Median Q1 Q3
1 a 10 310.6667 245.1957 283.1503
2 b 10 300.8500 294.2031 297.7674
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 54
n(small)= 10 , n(big)= 10
P_estimate = 0.7913368 ,P_exact = 0.7623688
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.7623688 ).
Analysis finished
###Distribution hypothesis####
Normality Test (Shapiro-Wilk): Failed (P = 0.02658585 )
Equal Variance Test (Brown-Forsythe): Passed (P = 0.163 )
Treatment_Name N Median Q1 Q3
1 a 10 303.4108 250.0425 279.3795
2 b 10 294.1081 279.7710 291.9993
###Dependent Variable: Indexvalue ####
###Mann-Whitney Rank Sum Test####
###Statistics####
Mann-Whitney U Statistic= 56
n(small)= 10 , n(big)= 10
P_estimate = 0.677585 ,P_exact = 0.6501474
###Conclusion####
The difference in the median values between the two groups is not great enough to exclude the possibility that the difference is due to random sampling variability; there is not a statistically significant difference (P = 0.6501474 ).
Analysis finished
3)可视化:
#柱状图
Alpha_results$plotlist$Plotobj_Shannon$Barplot
#箱线图
Alpha_results$plotlist$Plotobj_Shannon$Boxplot
#小提琴图
Alpha_results$plotlist$Plotobj_Shannon$Violinplot
4)差异检验:
Alpha_results$plotlist$Plotobj_Shannon$Statistics
5)提取计算结果并自定义可视化:
####提取计算结果并基于ggplot2包自定义绘图
library(ggsignif) # Significance Brackets for 'ggplot2'
data_Alpha <- Alpha_results$alphaframe
#Shannon
p1 <- ggplot(data_Alpha[data_Alpha$Indexname=="Shannon",],
aes(group2, Indexvalue, fill = group2))+
geom_boxplot(width=0.8,outlier.color =NA)+
geom_jitter(aes(fill = group2), shape = 21, color = "black",size = 2.5,width = 0.2)+
theme_bw() +
theme(axis.title = element_text(size = 18),
panel.grid = element_blank(),
axis.text = element_text( size = 13),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),limits = c(4,6.5))+
labs(x=NULL,y="Shannon")+
geom_signif(comparisons = list(c("e","f")),
map_signif_level = T, #使用*号显示显著性
test = "t.test",#检验方法
textsize = 4,#字号大小
y_position = c(6.2),#横线位置
tip_length = c(0),#横线下方线条的长度
size=0.8,color="black")#线条颜色及粗细
#Simpson
p2 <- ggplot(data_Alpha[data_Alpha$Indexname=="Simpson",],
aes(group2, Indexvalue, fill = group2))+
geom_boxplot(width=0.8,outlier.color =NA)+
geom_jitter(aes(fill = group2), shape = 21, color = "black",size = 2.5,width = 0.2)+
theme_bw() +
theme(axis.title = element_text(size = 18),
panel.grid = element_blank(),
axis.text = element_text( size = 13),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),limits = c(0.72,0.95))+
labs(x=NULL,y="Simpson")+
geom_signif(comparisons = list(c("e","f")),
map_signif_level = T, #使用*号显示显著性
test = "t.test",#检验方法
textsize = 4,#字号大小
y_position = c(0.92),#横线位置
tip_length = c(0),#横线下方线条的长度
size=0.8,color="black")#线条颜色及粗细
#ACE
p3 <- ggplot(data_Alpha[data_Alpha$Indexname=="ACE",],
aes(group2, Indexvalue, fill = group2))+
geom_boxplot(width=0.8,outlier.color =NA)+
geom_jitter(aes(fill = group2), shape = 21, color = "black",size = 2.5,width = 0.2)+
theme_bw() +
theme(axis.title = element_text(size = 18),
panel.grid = element_blank(),
axis.text = element_text( size = 13),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),limits = c(290,880))+
labs(x=NULL,y="ACE")+
geom_signif(comparisons = list(c("e","f")),
map_signif_level = T, #使用*号显示显著性
test = "t.test",#检验方法
textsize = 4,#字号大小
y_position = c(800),#横线位置
tip_length = c(0),#横线下方线条的长度
size=0.8,color="black")#线条颜色及粗细
#Chao
p4 <- ggplot(data_Alpha[data_Alpha$Indexname=="Chao",],
aes(group2, Indexvalue, fill = group2))+
geom_boxplot(width=0.8,outlier.color =NA)+
geom_jitter(aes(fill = group2), shape = 21, color = "black",size = 2.5,width = 0.2)+
theme_bw() +
theme(axis.title = element_text(size = 18),
panel.grid = element_blank(),
axis.text = element_text( size = 13),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),limits = c(290,880))+
labs(x=NULL,y="Chao")+
geom_signif(comparisons = list(c("e","f")),
map_signif_level = T, #使用*号显示显著性
test = "t.test",#检验方法
textsize = 4,#字号大小
y_position = c(800),#横线位置
tip_length = c(0),#横线下方线条的长度
size=0.8,color="black")#线条颜色及粗细
library(patchwork)
p1+p2+p3+p4
更多内容大家请阅读LorMe包的帮助文档!
参考:LorMe包帮助文档
微生物组系列推文合集:
扩增子测序数据分析还不会?小编整理的全套R语言代码助您轻松解决问题!(更新版)
「微生物组」基于microeco包进行共现性网络分析!!!
「微生物组」基于microeco包进行lefsef分析及随机森林分析!!!
「微生物组」Stamp结果图复现——分组差异图的绘制!!!
「微生物组」基于microeco包进行环境数据关联分析—以RDA分析为例!!!
「微生物组」基于microeco包进行共享/独特OTU计算及可视化!!!
「微生物组」基于microeco包进行Alpha多样性分析!!!
「微生物组」基于microeco包进行微生物群落结构组成分析!!!
R可视化——Mantel test分析及可视化
基于R语言的微生物群落组成多样性分析——α多样性及其可视化
基于R语言的微生物群落组成多样性分析—β多样性之PCoA分析
基于R语言的微生物群落组成多样性分析—β多样性之组间差异性检验
基于R语言的微生物群落组成多样性分析——物种丰度计算及可视化
基于R语言的微生物群落组成多样性分析——物种丰度可视化之热图(Heatmap)
基于R语言的微生物群落组成多样性分析——物种丰度可视化之弦图(Chord Diagram)
基于R语言的微生物群落组成多样性分析——共线性网络分析
基于R语言的微生物群落组成多样性分析——RDA分析
基于R语言的微生物群落组成多样性分析——CCA分析
基于R语言的微生物群落组成多样性分析——PCA分析
基于R语言的微生物群落组成多样性分析——聚类分析
基于LEfSe分析进行微生物物种差异及关联分析
基于R语言的微生物群落组成分析—差异OTU筛选及展示
基于R语言的微生物群落组成多样性分析——NMDS分析
基于R语言的微生物群落组成分析—α多样性指数的正态分布检验及差异性标注()
R可视化——基于MicrobiomeStat包进行微生物组数据分析(更新版)!!!
基于R语言进行扩增子数据的UMAP分析!
R可视化——共现性网络分析第二弹
R可视化——基于MicrobiotaProcess包进行物种群落结构组成分析!
R可视化——基于MicrobiotaProcess包进行物种差异分析!
基于microeco包进行PCoA分析!!!
基于MicrobiotaProcess包进行PCoA分析!
R可视化——基于MicrobiotaProcess包进行Alpha多样性分析!
PS: 以上内容是小编个人学习代码笔记分享,仅供参考学习,欢迎大家一起交流学习。
R绘图模板合集(包括附带注释的源码、测试数据及绘制效果图)可在公众号后台菜单栏查看具体获取方式!绘图模板合集效果图展示: