├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── EasyStat.Rproj ├── EasyStat_help.Rmd ├── EasyStat_help.html ├── NAMESPACE ├── R ├── BarP.R ├── BoxBarP.R ├── BoxP.R ├── Boxp2.R ├── FacetMuiPlotReBoxBar.R ├── FacetMuiPlotresultBar.R ├── FacetMuiPlotresultBox.R ├── FacetMuiPlotresultBox2.R ├── GroupBar.R ├── KwWlx.R ├── KwWlxPair.R ├── MuiHeatmapBubplot.R ├── MuiKwWlx.R ├── MuiKwWlxPair.R ├── MuiNorCV.R ├── MuiPlotFlowBar.R ├── MuiPlotReBoxBar.R ├── MuiPlotStackBar.R ├── MuiPlotresultBar.R ├── MuiPlotresultBox.R ├── MuiPlotresultBox2.R ├── MuiStat.R ├── MuiaovMcomper.R ├── NorNorCVTest.R ├── SingleStat.R ├── aovMcomper.R ├── ord_sig.R ├── util.R └── value_stackBar.R ├── README.md ├── data ├── data_wt.rda ├── env.rda ├── ps1.rda └── ps2.rda └── man ├── FacetMuiPlotReBoxBar.Rd ├── FacetMuiPlotresultBar.Rd ├── FacetMuiPlotresultBox.Rd ├── FacetMuiPlotresultBox2.Rd ├── GroupBar.Rd ├── KwWlx.Rd ├── KwWlx2.Rd ├── KwWlxPair.Rd ├── MuiHeatmapBubplot.Rd ├── MuiKwWlx.Rd ├── MuiKwWlx2.Rd ├── MuiKwWlxPair.Rd ├── MuiNorCV.Rd ├── MuiPlotReBoxBar.Rd ├── MuiPlotStackBar.Rd ├── MuiPlotresultBar.Rd ├── MuiPlotresultBox.Rd ├── MuiStat.Rd ├── MuiaovMcomper.Rd ├── MuiaovMcomper2.Rd ├── NorNorCVTest.Rd ├── SingleStat.Rd ├── aovMcomper.Rd ├── aovMcomper2.Rd ├── aovMuiBarPlot.Rd ├── aovMuiBoxBarP.Rd ├── aovMuiBoxP.Rd ├── aovMuiBoxP2.Rd ├── ord_sig.Rd └── value_stackBar.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: EasyStat 2 | Type: Package 3 | Title: What the Package Does (Title Case) 4 | Version: 0.1.0 5 | Author: Who wrote it 6 | Maintainer: The package maintainer 7 | Description: More about what it does (maybe more than one line) 8 | Use four spaces when indenting paragraphs within the Description. 9 | License: What license is it under? 10 | Encoding: UTF-8 11 | LazyData: true 12 | RoxygenNote: 7.1.1 13 | Imports: 14 | dplyr, 15 | tidyr, 16 | multcomp, 17 | agricolae, 18 | ggpubr, 19 | multcompView, 20 | reshape2, 21 | plyr, 22 | aplot 23 | URL: https://github.com/taowenmicro/EasyStat 24 | BugReports: https://github.com/taowenmicro/EasyStat/issues 25 | -------------------------------------------------------------------------------- /EasyStat.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /EasyStat_help.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "EasyStat_help" 3 | author: "wentao" 4 | date: "2020/6/13" 5 | output: html_document 6 | --- 7 | ```{css include=FALSE} 8 | pre code,pre,code { 9 | white-space:pre!important; 10 | overflow-x: scroll!important; 11 | } 12 | ``` 13 | 14 | ```{r setup, include=FALSE} 15 | knitr::opts_chunk$set(echo = TRUE, 16 | fig.width = 12, 17 | fig.height = 5, 18 | fig.align = "center", 19 | warning = FALSE, 20 | message = FALSE 21 | 22 | ) 23 | ``` 24 | 25 | # 差异分析完整解决方案 26 | 27 | 2020年11月更新: 28 | - 将ord_sig函数内置到差异分析中,改变水平排布顺序,更加符合常规认识。,单个指标方差检验和非参数检验已完成 29 | - KwWlx分参数检验字母标记混乱问题修正。 30 | 31 | 32 | 本次更新:2020年7月 33 | 34 | - 修改整个R包,包括包名;安装EasyStat包,本次安装包只要你可以用下载,应该可以安装成功。因为我已经将全部的依赖都写好了. 35 | - 增加多组展示同一张图的可视化方式。 36 | - 修改字母标记无法显示完整问题 37 | - 增加line展示差异ns是否显示的参数。 38 | - 增加线柱图展示。参考(NBT线虫工程菌)。 39 | 40 | 41 | 42 | ## EasyStat 使用指南 43 | 44 | 45 | 46 | 47 | ```{R eval=FALSE, include=FALSE} 48 | library(devtools) 49 | remotes::install_github("taowenmicro/EasyStat") 50 | # 如果国外不可用,则使用国内码云安装 51 | remotes::install_git('https://gitee.com/wentaomicro/EasyStat') 52 | ``` 53 | 54 | 导入包和数据,数据均来自真实试验和文公开文献下载,通过调整分组加入。 55 | 56 | ```{R} 57 | # 导入差异分析包 58 | library(EasyStat) 59 | library(ggplot2)# 用于作图 60 | library("dplyr")# 用于数据处理 61 | 62 | 63 | # #使用内置数据1 64 | # data(data_wt) 65 | # #内置数据2 66 | # data(env) 67 | 68 | 69 | ``` 70 | 71 | 72 | 73 | ### 基于单个指标的统计分析 74 | 75 | 正态检验和方差齐性分析,使用?NorNorCVTest查看帮助信息 76 | 77 | 78 | ```{R} 79 | # 使用?NorNorCVTest查看帮助信息 80 | ##使用案例 81 | NorCV = NorNorCVTest(data = data_wt, i= 4,method_cv = "leveneTest") 82 | 83 | #提取正态检验结果 84 | NorCV[[1]] 85 | 86 | # No Name W p.value norm.test 87 | # 1 1 CF 0.9385422 0.6474760 Norm 88 | # 2 2 CK 0.9306138 0.5848500 Norm 89 | # 3 3 Rhi 0.9651627 0.8585061 Norm 90 | # 4 4 WT 0.9756280 0.9278774 Norm 91 | # 5 Test Method: Shapiro-Wilk NA NA 92 | 93 | #提取方差齐性检验结果 94 | NorCV[[2]] 95 | # [1] 0.247 96 | 97 | ``` 98 | 99 | norm.test会按照分组告诉大家是否符合正态分布。 100 | 101 | ### 方差分析(aovMcomper) 102 | 103 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 104 | 105 | - i:代表您想要进行统计的列,比如:第三列:i = 3 106 | 107 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 108 | 109 | ```{R} 110 | 111 | # ?aovMcomper 112 | 113 | result= aovMcomper (data = data_wt, i= 6,method_Mc = "Tukey") 114 | 115 | 116 | # 提取多重比较结果 117 | result[[1]] 118 | 119 | # result[[1]] = ord_sig(data = result[[1]],ID = "groups") 120 | 121 | # groups group 122 | # CF a CF 123 | # CK a CK 124 | # Rhi b Rhi 125 | # WT a WT 126 | #提取方差检验结果 127 | result[[2]] 128 | 129 | # Call: 130 | # aov(formula = count ~ group, data = ss) 131 | # 132 | # Terms: 133 | # group Residuals 134 | # Sum of Squares 169573500000 3387000000 135 | # Deg. of Freedom 3 20 136 | # 137 | # Residual standard error: 13013.45 138 | # Estimated effects may be unbalanced 139 | 140 | ``` 141 | 142 | 结果中多重比较的展示全部使用字母表示了,虽然许多多种比较方法默认展示方式不同,但是我已经在包中将这些展示方式调整一致为字母。 143 | 144 | 145 | ### 非参数检验 146 | 147 | 两个参数代表的意义与方差分析的两个相同; 148 | 149 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 150 | 151 | - i:代表您想要进行统计的列,比如:第三列:i = 3 152 | 153 | 154 | ```{R} 155 | # ?KwWlx 156 | res = KwWlx(data = data_wt, i= 6) 157 | 158 | # 调用非参数两两比较结果:字母标记展示 159 | res[[1]] 160 | 161 | # groups group 162 | # CF ab CF 163 | # CK a CK 164 | # Rhi c Rhi 165 | # WT b WT 166 | 167 | #表格展示两两之间差异结果 168 | res[[2]] 169 | 170 | # .y. group1 group2 p p.adj p.format p.signif method 171 | # 172 | # 1 count CF CK 0.123 0.25 0.1228 ns Wilcoxon 173 | # 2 count CF Rhi 0.00470 0.028 0.0047 ** Wilcoxon 174 | # 3 count CF WT 0.864 0.86 0.8643 ns Wilcoxon 175 | # 4 count CK Rhi 0.00470 0.028 0.0047 ** Wilcoxon 176 | # 5 count CK WT 0.0488 0.15 0.0488 * Wilcoxon 177 | # 6 count Rhi WT 0.00470 0.028 0.0047 ** Wilcoxon 178 | 179 | ``` 180 | 181 | ## 差异可视化方案(两种差异表示,三种图形展示) 182 | 183 | 184 | ### 柱状图展示方差分析或非参数检验结果(aovMuiBarPlot) 185 | 186 | 在这个包中将差异检测和出图部分分离,方便选择合适的图表和差异可视化的策略。最终要的参数是result :为前面差异分析结果中的第一个表单,格式为第一列差异显著字母,第二列分组标签,列名,分组标签。如果只是用可视化的函数,直接从外面导入类似数据即可。 187 | 188 | ```{R} 189 | 190 | data_wt$fun 191 | # ?aovMuiBarPlot 192 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 193 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 6,sig_show ="abc",result = result[[1]]) 194 | #提取结果 195 | p1 <- PlotresultBar[[1]] 196 | 197 | 198 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 6,sig_show ="abc",result = res[[1]]) 199 | #提取结果 200 | p2 <- PlotresultBar[[1]] 201 | 202 | 203 | library(patchwork) 204 | p1+p2 205 | 206 | 207 | ``` 208 | 209 | #### 标记字母顺序修改ord_sig 210 | 211 | 212 | ```{R} 213 | 214 | datord <- ord_sig(data = result[[1]],ID = "groups") 215 | 216 | # ?aovMuiBarPlot 217 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 218 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 6,sig_show ="abc",result =datord) 219 | #提取结果 220 | p <- PlotresultBar[[1]] 221 | p 222 | 223 | ``` 224 | 225 | ```{R} 226 | # ?aovMuiBarPlot 227 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 228 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 6,sig_show ="line",result = result[[1]]) 229 | #提取结果 230 | p <- PlotresultBar[[1]] 231 | 232 | 233 | p 234 | 235 | 236 | # ggsave("2.png",p) 237 | #提取方差分析或非参数检验结果 238 | PlotresultBar[[2]] 239 | ``` 240 | 241 | 242 | ```{R} 243 | # ?aovMuiBarPlot 244 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 245 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 5,sig_show ="line",result = result[[1]],ns =TRUE) 246 | #提取结果 247 | p <- PlotresultBar[[1]] 248 | ggsave("3.png",p) 249 | #提取方差分析或非参数检验结果 250 | PlotresultBar[[2]] 251 | ``` 252 | 253 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 254 | 255 | - i:代表您想要进行统计的列,比如:第三列:i = 3 256 | 257 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 258 | 259 | - result:代表显著性差异分析结果,是一个数据框,第一列是显著性差异字母,第二列是分组group 260 | 261 | #### 箱线图展示方差分析或非参数检验结果(aovMuiBoxP) 262 | 263 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 264 | 265 | - i:代表您想要进行统计的列,比如:第三列:i = 3 266 | 267 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 268 | 269 | - result:代表显著性差异分析结果,是一个数据框,第一列是显著性差异字母,第二列是分组group 270 | 271 | ```{R} 272 | 273 | datord <- ord_sig(data = result[[1]],ID = "groups") 274 | 275 | # ?aovMuiBoxP 276 | # #使用案例 277 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 6,sig_show ="abc",result = datord) 278 | # 提取检验结果 279 | PlotresultBox[[2]] 280 | #提取图片 281 | p = PlotresultBox[[1]] 282 | p 283 | 284 | # ggsave("4.png",p) 285 | 286 | ``` 287 | 288 | 289 | ```{R} 290 | # ?aovMuiBoxP 291 | # #使用案例 292 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 6,sig_show ="line",result = result[[1]]) 293 | # 提取检验结果 294 | PlotresultBox[[2]] 295 | #提取图片 296 | p = PlotresultBox[[1]] 297 | 298 | p 299 | # ggsave("5.png",p) 300 | 301 | ``` 302 | 303 | 304 | ```{R} 305 | # ?aovMuiBoxP 306 | # #使用案例 307 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 6,sig_show ="line",result = result[[1]],ns = TRUE) 308 | # 提取检验结果 309 | PlotresultBox[[2]] 310 | #提取图片 311 | p = PlotresultBox[[1]] 312 | # ggsave("6.png",p) 313 | 314 | ``` 315 | 316 | 317 | ### 点柱图-完美解决柱状图无法展示样本信息的缺陷 318 | 319 | ```{R} 320 | result= aovMcomper (data = data_wt, i= 6,method_Mc = "Tukey") 321 | # # 提取多重比较结果 322 | result[[1]] 323 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 6,sig_show ="abc",result = result[[1]],ns = TRUE) 324 | #提取图片 325 | p = PlotresultBox[[1]] 326 | 327 | p 328 | # ggsave("7.png",p) 329 | ``` 330 | 331 | ```{R} 332 | 333 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 6,sig_show ="line",result = result[[1]],ns = FALSE) 334 | #提取图片 335 | p = PlotresultBox[[1]] 336 | p 337 | 338 | # ggsave("8.png",p) 339 | ``` 340 | 341 | EasyStat包为什么能完美解决差异分析呢.因为他比你想象的要强大。下面使用连线形式展示差异,显著的差异按照标注星号,不显著的标注ns。 342 | 343 | ```{R} 344 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 6,sig_show ="line",result = result[[1]],ns = TRUE) 345 | #提取图片 346 | p = PlotresultBox[[1]] 347 | p 348 | ggsave("9.png",p) 349 | ``` 350 | 351 | ## 多指标模式 352 | 353 | ### 多个指标同时做正态检验和方差齐性分析(MuiNorCV) 354 | 355 | 这里对多组数据进行分析,结果我是用T或F代表,方便阅读。 356 | 357 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 358 | 359 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 360 | 361 | - method_cv:代表选择方差齐性的方法,有两种可供选择:method_cv == "bartlett.test" ;method_cv == "leveneTest" 362 | 363 | 364 | 365 | ```{R} 366 | dim(data_wt) 367 | # ?MuiNorCV 368 | # 使用案例 369 | norCv = MuiNorCV(data = data_wt,num = c(4:10),method_cv = "leveneTest") 370 | #展示正态检验和方差齐性结果 371 | norCv 372 | 373 | ``` 374 | 这里由于指标比较多,所以我将结果进行简化,直接使用ture和false来提示大家,cor是正态性检测组,cv是方差齐性检测。 375 | 376 | #### 多个指标方差检验(MuiaovMcomper) 377 | 378 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 379 | 380 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 381 | 382 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc = "LSD";method_Mc = "SNK";method_Mc = "Duncan";method_Mc ="scheffe" 383 | 384 | 385 | ```{R} 386 | # ? MuiaovMcomper 387 | # #使用案例 388 | result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 389 | #提取每个指标方差检验多重比较结果 390 | result 391 | 392 | # result = ord_sig(result, ID = NULL) 393 | 394 | ``` 395 | 同样,多个指标展示按照指标每列为一组检测结果。 396 | 397 | ### 多个指标非参数检验(MuiKwWlx) 398 | 399 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 400 | 401 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 402 | 403 | ```{R} 404 | # ? MuiKwWlx 405 | # #使用案例 406 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 407 | #提取每个指标非参数检验多重比较结果 408 | result 409 | 410 | # result = ord_sig(result, ID = NULL) 411 | 412 | ``` 413 | 414 | 结果和多组方差分析结果一样。很好用于后面的出图,同样也适合自己导入数据,使用出图 415 | 416 | 417 | ### 多组数据可视化差异分析结果: 柱状图(MuiPlotresultBar) 418 | 419 | 多组指标分开出图,比较麻烦的是图形的保存,如果还需要让你一个一个保存图片,那也是相当繁琐的,所以这里我设置了自动保存,也只有这种方式是自动保存,其他单个,多组分面图形较少,所以就可以自己保存。 420 | 421 | 我让该函数自动保存每个指标的出图文件到当前文件夹中。这些文件以该指标名称命名; 422 | 423 | 424 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 425 | 426 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 427 | 428 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 429 | 430 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 431 | 432 | ```{R} 433 | # ?MuiPlotresultBar 434 | # # #使用案例 435 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 436 | result 437 | # #结果直接输出到文件夹中 438 | MuiPlotresultBar(data = data_wt,num = c(4:6),result = result ,sig_show ="line") 439 | 440 | 441 | ``` 442 | 443 | ### 多组数据可视化差异分析结果:箱线图(MuiPlotresultBox) 444 | 445 | 我让该函数自动保存每个指标的出图文件到当前文件夹中。这些文件以该指标名称命名; 446 | 447 | 448 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 449 | 450 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 451 | 452 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 453 | 454 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 455 | ```{R} 456 | # ?MuiPlotresultBox 457 | #使用案例 458 | result = MuiKwWlx(data = data_wt,num = c(4:8)) 459 | result 460 | # #直接出图到文件夹中 461 | MuiPlotresultBox(data = data_wt,num = c(4:8),result = result,sig_show ="abc") 462 | 463 | ``` 464 | 465 | ### 线柱图 466 | 467 | 输入和箱线图一致 468 | ```{R} 469 | # ?MuiPlotresultBox 470 | #使用案例 471 | result = MuiKwWlx(data = data_wt,num = c(4:8)) 472 | result 473 | # #直接出图到文件夹中 474 | MuiPlotReBoxBar(data = data_wt,num = c(4:8),result = result,sig_show ="line") 475 | 476 | ``` 477 | 478 | #### 差异结果展示:分面展示柱状图:(FacetMuiPlotresultBar) 479 | 480 | 更新: 481 | - 由于不同指标坐标轴范围不同,分面添加显著性标示会让最高点的标示遮盖,已解决 482 | 483 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 484 | 485 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 486 | 487 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 488 | 489 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 490 | - ncol:代表分面展示每一行放几张图 491 | 492 | ```{R} 493 | 494 | library(ggplot2) 495 | # ?FacetMuiPlotresultBar 496 | # # #使用案例 497 | # data_wt$group = factor( data_wt$group,levels = c("WT","CK","Rhi","CF")) 498 | result = MuiaovMcomper(data = data_wt,num = c(4:7),method_Mc = "Tukey") 499 | result 500 | 501 | 502 | result1 = FacetMuiPlotresultBar(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4 ) 503 | p <- result1[[1]] 504 | p 505 | 506 | # ggsave("10.png",p,width = 12,height = 6) 507 | 508 | ``` 509 | #### 设置分面排布顺序 510 | 511 | fac.level参数,指定即可。 512 | 513 | ```{R} 514 | 515 | colnames( data_wt)[4:7] 516 | 517 | result1 = FacetMuiPlotresultBar(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4, 518 | fac.level = c("fun","bac","AP","micro") ) 519 | p <- result1[[1]] 520 | p 521 | ``` 522 | 523 | ### 差异结果展示:分面展示箱线图:(FacetMuiPlotresultBox) 524 | 525 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 526 | 527 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 528 | 529 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 530 | 531 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 532 | 533 | - ncol:代表分面展示每一行放几张图 534 | 535 | 536 | ```{R} 537 | # ?FacetMuiPlotresultBox 538 | # #使用案例 539 | result = MuiKwWlx(data = data_wt,num = c(4:7)) 540 | result 541 | # 542 | result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4 ) 543 | p <- result1[[1]] 544 | ggsave("11.png",p,width = 15,height = 6) 545 | ``` 546 | 547 | 548 | #### 指定分面顺序 549 | 550 | 551 | ```{R} 552 | 553 | colnames( data_wt)[4:7] 554 | 555 | result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4, 556 | fac.level = c("fun","bac","AP","micro") ) 557 | p <- result1[[1]] 558 | p 559 | ``` 560 | 561 | 562 | 使用两种方法,我们可以对比非参数检验和方差检验结果是否一致 563 | 564 | ### 下面使用线柱图展示 565 | 566 | 567 | ```{R} 568 | # #使用案例 569 | result = MuiKwWlx(data = data_wt,num = c(4:7)) 570 | result 571 | # 572 | result1 = FacetMuiPlotReBoxBar(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4 ) 573 | p <- result1[[1]] 574 | ggsave("12.png",p,width = 15,height = 6) 575 | 576 | ``` 577 | 578 | #### 指定分面顺序 579 | 580 | ```{R} 581 | 582 | colnames( data_wt)[4:7] 583 | 584 | result1 =FacetMuiPlotReBoxBar(data = data_wt,num = c(4:7),result = result,sig_show ="abc",ncol = 4, 585 | fac.level = c("fun","bac","AP","micro") ) 586 | p <- result1[[1]] 587 | p 588 | ``` 589 | 590 | 注意以上三种分面展示的目前仅支持字母标注显著性,连线形式的尚未添加。 591 | 592 | ### 多个分组可视化:GroupBar 593 | 594 | 使用这种方式可视化一定要注意,坐标轴量度,不同指标范围不一样,因此,单位差距极大的指标一起展示就不太好看了。其次,这里使用line展示会非常混乱,所以我去除了line展示的方式,所以这里没有选择,只能是默认的abc。但是我保留了这个参数,希望以后又更好的方式。 595 | 596 | - ylimit = 1.2 :设置Y轴上界范围 597 | 598 | ```{R} 599 | colnames(data_wt) 600 | result = MuiKwWlx(data = data_wt,num = c(8:10)) 601 | result = GroupBar(data = data_wt,num = c(8:10),result = result,sig_show ="abc",ylimit = 1.2) 602 | # output result 603 | p <- result[[1]] 604 | ggsave("13.png",p) 605 | 606 | ``` 607 | 608 | 这里我想告诉大家,所有的出图函数都可以提取数据,并且自己设计代码出图。 609 | 610 | 这里我们提取数据,直接出图也是可以的 611 | 612 | ```{R} 613 | 614 | A = result[[2]] 615 | 616 | p<-ggplot(A, aes(x=group , y=mean,group = name ))+ 617 | geom_bar(aes(colour= name,fill = name),stat = "identity", width = 0.9,position = "dodge") + 618 | 619 | geom_errorbar(aes(ymin=mean - SD, 620 | ymax=mean + SD,group = name), 621 | colour="black",width=0.1,size = 1,position = position_dodge(.9))+ 622 | 623 | scale_y_continuous(expand = c(0,0))+#,limits = c(0,a) 624 | labs( 625 | y="count" 626 | # y=name_i 627 | # title = paste("Normality test",p1,"Homogeneity of variance",p2,sep = ":") 628 | ) + 629 | geom_text(data=A, aes(x=group, y=mean +SD ,label=groups),position = position_dodge(.9),vjust = -1)+ 630 | guides(color=guide_legend(title = NULL),shape=guide_legend(title = NULL)) 631 | p 632 | 633 | ggsave("14.png",p,width = 12,height = 6) 634 | 635 | ``` 636 | 637 | 638 | 639 | ### 单个指标一体化分析(SingleStat) 640 | 641 | 这个函数可以将我们的目标列做正态检验和方差齐性,然后根据结果选择方差检验或者多重比较方法,最后选择自己需要的出图方式和显著性标记方式展示。 642 | 643 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 644 | 645 | - i:代表您想要进行统计的列,比如:第三列:i = 3 646 | 647 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 648 | 649 | - plot:可以选择需要的出图类型,柱状图和箱线图 650 | 651 | 652 | ```{R} 653 | # ?SingleStat 654 | # # #使用案例 655 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 656 | result = SingleStat(data = data_wt,plot = "bar",method_Mc = "Tukey",i= 4,sig_show ="abc") 657 | # #导出图片 658 | p = result[[1]] 659 | p 660 | 661 | ggsave("15.png",p,width = 6,height = 6) 662 | 663 | ``` 664 | 665 | 666 | 可以更换出图方式,当然这里会自动判断使用方差分析,还是非参数检验。选择结果会展示在结果的第三个列表中,可自行查看。 667 | 668 | 669 | ```{R} 670 | # ?SingleStat 671 | # # #使用案例 672 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 673 | result = SingleStat(data = data_wt,plot = "box",method_Mc = "Tukey",i= 4,sig_show ="abc") 674 | # 提取差异检测结果 675 | result[[2]] 676 | # 提取差异检测放啊 677 | result[[3]] 678 | 679 | # #导出图片 680 | p = result[[1]] 681 | p 682 | ggsave("16.png",p,width = 6,height = 6) 683 | 684 | 685 | ``` 686 | 687 | 688 | 689 | ```{R} 690 | # ?SingleStat 691 | # # #使用案例 692 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 693 | result = SingleStat(data = data_wt,plot = "boxbar",method_Mc = "Tukey",i= 4,sig_show ="abc") 694 | # 提取差异检测结果 695 | result[[2]] 696 | # 提取差异检测放啊 697 | result[[3]] 698 | 699 | # #导出图片 700 | p = result[[1]] 701 | p 702 | 703 | ggsave("17.png",p,width = 6,height = 6) 704 | 705 | 706 | ``` 707 | 708 | 709 | 710 | 711 | ### 多个指标一体化分析(MuiStat) 712 | 713 | 实现了多个指标批量整体运行;这个函数可以将我们的目标列做正态检验和方差齐性,然后根据结果选择方差检验或者多重比较方法,最后选择自己需要的出图方式和显著性标记方式展示。 714 | 715 | ```{R} 716 | # ?MuiStat 717 | #使用案例 718 | result = MuiStat(data = data_wt,num = c(4:7),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "box",plottype = "mui") 719 | p <- result[[1]] 720 | p 721 | # 提取方差检测的列 722 | result$aov 723 | # 提取f非参数检测的列 724 | result$wlx 725 | # 提取差异检测结果 726 | result$table 727 | 728 | ggsave("18.png",p,width = 16,height = 6) 729 | 730 | ``` 731 | 732 | 柱状图 733 | 734 | ```{R} 735 | 736 | result = MuiStat(data = data_wt,num = c(4:7),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "bar",plottype = "mui") 737 | p <- result[[1]] 738 | 739 | ggsave("19.png",p,width = 16,height = 6) 740 | 741 | 742 | ``` 743 | 744 | ```{R} 745 | 746 | result = MuiStat(data = data_wt,num = c(4:7),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "boxbar",plottype = "mui") 747 | p <- result[[1]] 748 | ggsave("20.png",p,width = 16,height = 6) 749 | 750 | ``` 751 | 752 | 753 | 754 | data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 755 | 756 | num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 757 | 758 | method_cv:代表选择方差齐性的方法,有两种可供选择:method_cv == "bartlett.test" ;method_cv == "leveneTest" 759 | 760 | method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 761 | 762 | plot:可以选择需要的出图类型,柱状图和箱线图 763 | 764 | sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 765 | 766 | ncol:代表分面展示每一行放几张图 767 | 768 | plottype:输出图形是分面展示plottype =mui,还是单张展示:plottype == "single" 769 | 770 | 771 | ```{R} 772 | result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 773 | res <- MuiPlotStackBar(data = data,i = c(4,9,8) ,result = result) 774 | 775 | 776 | res[[1]] 777 | ``` 778 | 779 | 780 | ```{R} 781 | 782 | # 由于数据已经标准化了,这里我们改编一下 783 | 784 | env$env4 <- env$env4^2 785 | env$env5 <- env$env5^2 786 | result = MuiKwWlx(data = env,num = c(3,4)) 787 | res <- MuiPlotStackBar(data = env,i = c(3,4) ,result = result,errbar = FALSE) 788 | ``` 789 | 790 | 791 | 792 | 793 | 794 | 795 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(FacetMuiPlotReBoxBar) 4 | export(FacetMuiPlotresultBar) 5 | export(FacetMuiPlotresultBox) 6 | export(FacetMuiPlotresultBox2) 7 | export(GroupBar) 8 | export(KwWlx) 9 | export(KwWlx2) 10 | export(KwWlxPair) 11 | export(MuiHeatmapBubplot) 12 | export(MuiKwWlx) 13 | export(MuiKwWlx2) 14 | export(MuiKwWlxPair) 15 | export(MuiNorCV) 16 | export(MuiPlotReBoxBar) 17 | export(MuiPlotStackBar) 18 | export(MuiPlotresultBar) 19 | export(MuiPlotresultBox) 20 | export(MuiStat) 21 | export(MuiaovMcomper) 22 | export(MuiaovMcomper2) 23 | export(NorNorCVTest) 24 | export(SingleStat) 25 | export(aovMcomper) 26 | export(aovMcomper2) 27 | export(aovMuiBarPlot) 28 | export(aovMuiBoxBarP) 29 | export(aovMuiBoxP) 30 | export(aovMuiBoxP2) 31 | export(ord_sig) 32 | export(value_stackBar) 33 | -------------------------------------------------------------------------------- /R/BarP.R: -------------------------------------------------------------------------------- 1 | #' Variance test or non-parametric test results visualization, using histogram 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param ns Logical value, whether to display insignificant marks 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' PlotresultBar = aovMuiBarPlot(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 12 | #' # utput result 13 | #' PlotresultBar[[1]] 14 | #' @return list 15 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 16 | #' @references 17 | #' 18 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 19 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 20 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 21 | #' @export 22 | 23 | 24 | 25 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 26 | aovMuiBarPlot = function(data = data_wt, i= 3,sig_show ="line",result = result,ns = FALSE){ 27 | 28 | name_i = colnames(data[i]) 29 | # the mean and variance 30 | wen1 = as.data.frame(tapply(as.vector(as.matrix(data[i])),data$group,mean,na.rm=TRUE)) 31 | wen2 = as.data.frame(tapply(as.vector(as.matrix(data[i])),data$group,sd,na.rm=TRUE)) 32 | went = cbind(wen1,wen2) 33 | colnames(went) = c("mean" ,"SD") 34 | aa = result 35 | wentao = merge(aa,went, by="row.names",all=F) 36 | 37 | aa = mutate(wentao, ymin = mean - SD, ymax = mean + SD) 38 | a = max(aa$ymax)*1.2## 39 | 40 | ### 41 | p = ggplot(aa , aes(x = group, y = mean,colour= group)) + 42 | geom_bar(aes(colour= group,fill = group),stat = "identity", width = 0.4,position = "dodge") + 43 | 44 | geom_errorbar(aes(ymin=ymin, 45 | ymax=ymax), 46 | colour="black",width=0.1,size = 1)+ 47 | scale_y_continuous(expand = c(0,0),limits = c(0,a))+# 48 | labs( 49 | # x=paste(name_i,"of all group", sep = "_"), 50 | y=name_i 51 | # title = paste("Normality test",p1,"Homogeneity of variance",p2,sep = ":") 52 | ) 53 | line = list() 54 | if (sig_show == "line") { 55 | zuhe = combn(aa$group,2) 56 | xxxx <- tapply(zuhe,rep(1:ncol(zuhe),each=nrow(zuhe)),function(i)i) 57 | xxxx 58 | sig_lis = rep("a",dim(zuhe)[2]) 59 | for (i in 1:dim(zuhe)[2]) { 60 | 61 | 62 | if (filter(aa, group == xxxx[[i]][1])$groups == filter(aa, group == xxxx[[i]][2])$groups) { 63 | sig_lis[i] = "no_sig" 64 | } 65 | 66 | if (filter(aa, group == xxxx[[i]][1])$groups != filter(aa, group == xxxx[[i]][2])$groups) { 67 | sig_lis[i] = "*" 68 | } 69 | 70 | } 71 | 72 | if (ns == TRUE) { 73 | #-remove the ns 74 | xxxx[as.character((1:length(sig_lis))[sig_lis =="no_sig"])] = NULL 75 | sig_lis = sig_lis[sig_lis != "no_sig"] 76 | } 77 | 78 | line = list(comparisons = xxxx,annotations=sig_lis,y_position = (seq(from=1, to=max(aa$mean)/4,length.out=dim(zuhe)[2]) + max(aa$mean)),tip_length = rep(0.03,dim(zuhe)[2])) 79 | 80 | p = p + 81 | ggsignif::geom_signif(comparisons = xxxx, annotations=sig_lis, 82 | y_position = (seq(from=1, to=max(aa$mean)/4,length.out=dim(zuhe)[2]) + max(aa$mean)), tip_length = rep(0.03,dim(zuhe)[2]),color = "black") 83 | p 84 | } 85 | 86 | 87 | if (sig_show == "abc") { 88 | 89 | 90 | p = p + geom_text(aes(label = groups,y=ymax, x = group,vjust = -0.3,size = 6)) 91 | p 92 | } 93 | 94 | p 95 | 96 | if (length(unique(data$group))>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 97 | 98 | return(list(p,wentao,aa,line)) 99 | } 100 | -------------------------------------------------------------------------------- /R/BoxBarP.R: -------------------------------------------------------------------------------- 1 | #' Variance test or non-parametric test results visualization, using boxbar 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param ns Logical value, whether to display insignificant marks 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 3,sig_show ="abc",result = result[[1]]) 12 | #' # utput result 13 | #' result[[1]] 14 | #' 15 | #' @return list 16 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 17 | #' @references 18 | #' 19 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 20 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 21 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 22 | #' @export 23 | 24 | 25 | aovMuiBoxBarP = function(data = data_wt, i= 3,sig_show ="line",result = result,ns = FALSE){ 26 | 27 | aa = result 28 | print(i) 29 | name_i = colnames(data[i]) 30 | name_i 31 | data_box = data[c(1,2,i)] 32 | colnames(data_box) = c("ID" , "group","dd" ) 33 | 34 | data_box$stat=aa[as.character(data_box$group),]$groups 35 | 36 | 37 | max=max(data_box[,c("dd")],na.rm = TRUE) 38 | min=min(data_box[,c("dd")],na.rm = TRUE) 39 | x = data_box[,c("group","dd")] 40 | 41 | y = x %>% group_by(group) %>% summarise_(Max=paste('max(',"dd",",na.rm = TRUE",')',sep="")) 42 | 43 | 44 | 45 | y=as.data.frame(y) 46 | y 47 | rownames(y)=y$group 48 | data_box$y=y[as.character(data_box$group),]$Max + (max-min)*0.05 49 | 50 | 51 | iris_groups<- group_by(data_box, group) 52 | databar<- dplyr::summarise(iris_groups, mean(dd,na.rm = TRUE), sd(dd,na.rm = TRUE)) 53 | colnames(databar) = c("group","mean","sd") 54 | 55 | head(databar) 56 | p = ggplot() + 57 | geom_bar(data = databar,aes(x= group,y = mean,fill = group),stat = "identity", width = 0.4,position = "dodge",colour= "black") + 58 | geom_errorbar(data = databar,aes(x= group,y = mean,ymin=mean -sd, ymax=mean +sd),colour="black",width=0.1,size = 1)+ 59 | geom_jitter(aes(x=group, y=dd, fill=group),data_box,position=position_jitter(0.17), size=4, alpha=0.7,pch = 21,color = "black")+ 60 | labs( 61 | y=name_i) 62 | # p 63 | # geom_hline(aes(yintercept=mean(data_box$dd)), colour="black", linetype=2) + 64 | # geom_vline(aes(xintercept=0), colour="black", linetype="dashed") 65 | head(data_box) 66 | if (sig_show == "abc") { 67 | p = p + 68 | geom_text(data=data_box, aes(x=group, y=y*1.1, label= stat)) 69 | 70 | p 71 | } 72 | 73 | 74 | wtq = levels(data$group) 75 | lis = combn(levels(data$group), 2) 76 | x <-lis 77 | my_comparisons <- tapply(x,rep(1:ncol(x),each=nrow(x)),function(i)i) 78 | 79 | 80 | if (sig_show == "line") { 81 | zuhe = combn(aa$group,2) 82 | xxxx <- tapply(zuhe,rep(1:ncol(zuhe),each=nrow(zuhe)),function(i)i) 83 | xxxx 84 | sig_lis = rep("a",dim(zuhe)[2]) 85 | for (i in 1:dim(zuhe)[2]) { 86 | library(tidyverse) 87 | 88 | if (filter(aa, group == xxxx[[i]][1])$groups == filter(aa, group == xxxx[[i]][2])$groups) { 89 | sig_lis[i] = "no_sig" 90 | } 91 | 92 | if (filter(aa, group == xxxx[[i]][1])$groups != filter(aa, group == xxxx[[i]][2])$groups) { 93 | sig_lis[i] = "*" 94 | } 95 | 96 | } 97 | 98 | # ns = TRUE 99 | # sig_lis[3] = "no_sig" 100 | # sig_lis[4] = "no_sig" 101 | 102 | if (ns == TRUE) { 103 | #-remove the ns 104 | xxxx[as.character((1:length(sig_lis))[sig_lis =="no_sig"])] = NULL 105 | sig_lis = sig_lis[sig_lis != "no_sig"] 106 | } 107 | 108 | 109 | p = p + 110 | ggsignif::geom_signif(aes(x=group, y=dd, fill=group),data_box,comparisons = xxxx, annotations=sig_lis, 111 | y_position = (seq(from=1, to=max(data_box$dd)/4,length.out=length(sig_lis)) + max(data_box$dd)), tip_length = rep(0.03,length(sig_lis)),color = "black") 112 | p 113 | } 114 | 115 | # p=p+Mytheme 116 | p 117 | return(list(p,data_box,databar)) 118 | } 119 | 120 | -------------------------------------------------------------------------------- /R/BoxP.R: -------------------------------------------------------------------------------- 1 | #' Variance test or non-parametric test results visualization, using boxplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param ns Logical value, whether to display insignificant marks 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' PlotresultBox = aovMuiBoxP(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 12 | #' # utput result 13 | #' p = PlotresultBox[[1]] 14 | #' p 15 | #' @return data frame 16 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 17 | #' @references 18 | #' 19 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 20 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 21 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 22 | #' @export 23 | 24 | 25 | ###----使用方差检验结果和多重比较结果做展示: 箱线图展示 26 | aovMuiBoxP = function(data = data_wt, i= 3,sig_show ="line",result = result,ns = FALSE){ 27 | aa = result 28 | name_i = colnames(data[i]) 29 | data_box = data %>% 30 | dplyr::select(1,2,i) 31 | colnames(data_box) = c("ID" , "group","dd" ) 32 | 33 | 34 | 35 | data_box$stat=aa[as.character(data_box$group),]$groups 36 | 37 | 38 | max=max(data_box[,c("dd")],na.rm = TRUE) 39 | min=min(data_box[,c("dd")],na.rm = TRUE) 40 | x = data_box[,c("group","dd")] 41 | y = x %>% group_by(group) %>% summarise_(Max=paste('max(',"dd",",na.rm = TRUE",')',sep="")) 42 | 43 | 44 | 45 | y=as.data.frame(y) 46 | y 47 | rownames(y)=y$group 48 | data_box$y=y[as.character(data_box$group),]$Max + (max-min)*0.05 49 | 50 | head(data_box) 51 | p = ggplot(data_box, aes(x=group, y=.data[["dd"]], color=group)) + 52 | geom_boxplot(alpha=1, outlier.size=0, size=0.7, width=0.5, fill="transparent") + 53 | labs( 54 | y=name_i)+ 55 | geom_jitter( position=position_jitter(0.17), size=1, alpha=0.7)+theme(legend.position="none") 56 | 57 | head(data_box) 58 | 59 | if (sig_show == "abc") { 60 | tab.abc = data_box %>% distinct( group, .keep_all = TRUE) 61 | p = p + 62 | geom_text(data=tab.abc, aes(x=group, y=y, color=group, label= stat)) 63 | 64 | p 65 | } 66 | wtq = levels(data$group) 67 | lis = combn(levels(as.factor(data$group)), 2) 68 | x <-lis 69 | my_comparisons <- tapply(x,rep(1:ncol(x),each=nrow(x)),function(i)i) 70 | 71 | line = list() 72 | if (sig_show == "line") { 73 | zuhe = combn(aa$group,2) 74 | xxxx <- tapply(zuhe,rep(1:ncol(zuhe),each=nrow(zuhe)),function(i)i) 75 | xxxx 76 | sig_lis = rep("a",dim(zuhe)[2]) 77 | for (i in 1:dim(zuhe)[2]) { 78 | if (filter(aa, group == xxxx[[i]][1])$groups == filter(aa, group == xxxx[[i]][2])$groups) { 79 | sig_lis[i] = "no_sig" 80 | } 81 | 82 | if (filter(aa, group == xxxx[[i]][1])$groups != filter(aa, group == xxxx[[i]][2])$groups) { 83 | sig_lis[i] = "*" 84 | } 85 | 86 | } 87 | 88 | if (ns == TRUE) { 89 | #-remove the ns 90 | xxxx[as.character((1:length(sig_lis))[sig_lis =="no_sig"])] = NULL 91 | sig_lis = sig_lis[sig_lis != "no_sig"] 92 | } 93 | 94 | line = list(comparisons = xxxx,annotations=sig_lis,y_position = (seq(from=1, to=max(data_box$dd)/4,length.out=dim(zuhe)[2]) + max(data_box$dd)),tip_length = rep(0.03,dim(zuhe)[2])) 95 | p = p + 96 | ggsignif::geom_signif(comparisons = xxxx, annotations=sig_lis, 97 | y_position = (seq(from=1, to=max(data_box$dd)/4,length.out=dim(zuhe)[2]) + max(data_box$dd)), tip_length = rep(0.03,dim(zuhe)[2]),color = "black") 98 | p 99 | } 100 | 101 | # p=p+Mytheme 102 | p 103 | 104 | return(list(p,data_box)) 105 | } 106 | -------------------------------------------------------------------------------- /R/Boxp2.R: -------------------------------------------------------------------------------- 1 | #' Variance test or non-parametric test results visualization, using boxplot paired line show pair com... 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i for col id or colames 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param ns Logical value, whether to display insignificant marks 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx2(data = data_wt, i= 4) 11 | #' PlotresultBox = aovMuiBoxP2(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 12 | #' # utput result 13 | #' p = PlotresultBox[[1]] 14 | #' p 15 | #' @return data frame 16 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 17 | #' @references 18 | #' 19 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 20 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 21 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 22 | #' @export 23 | 24 | 25 | ###----使用方差检验结果和多重比较结果做展示: 箱线图展示 26 | aovMuiBoxP2 = function(data = data_wt, i= 3,sig_show ="line",result = result,ns = FALSE){ 27 | aa = result 28 | name_i = colnames(data[i]) 29 | data_box = data %>% 30 | dplyr::select(1,2,i) 31 | colnames(data_box) = c("ID" , "group","dd" ) 32 | 33 | 34 | data_box$stat=aa[as.character(data_box$group),]$groups 35 | 36 | 37 | max=max(data_box[,c("dd")],na.rm = TRUE) 38 | min=min(data_box[,c("dd")],na.rm = TRUE) 39 | x = data_box[,c("group","dd")] 40 | y = x %>% group_by(group) %>% summarise_(Max=paste('max(',"dd",",na.rm = TRUE",')',sep="")) 41 | 42 | 43 | 44 | y=as.data.frame(y) 45 | y 46 | rownames(y)=y$group 47 | data_box$y=y[as.character(data_box$group),]$Max + (max-min)*0.05 48 | data_box <- data_box %>% arrange(group) 49 | 50 | 51 | data_box$pid = rep(1:(dim(data_box)[1]/unique(data_box$group) %>% length()),(unique(data_box$group) %>% length())) 52 | head(data_box) 53 | 54 | # p = ggpubr::ggpaired(data_box, x = "group", y = "dd",id="pid", 55 | # color = "group", palette = "lancet", point.size=2,linetype=2, 56 | # line.color = "gray", outlier.size=0, size=0.7, width=0.5, fill="transparent", 57 | # short.panel.labs = FALSE) + 58 | # labs(y=name_i) 59 | # 60 | # p 61 | p = ggplot(data_box, aes(x=group, y=.data[["dd"]], color=group)) + 62 | geom_boxplot(alpha=1, outlier.size=0, size=0.7, width=0.5, fill="transparent") + 63 | labs( 64 | y=name_i)+ 65 | geom_point( size=1, alpha=0.7)+theme(legend.position="none") + 66 | geom_line(data = data_box,aes(x = group,y = dd,group = pid),color = "grey80" ) + 67 | labs(y=name_i) 68 | 69 | 70 | 71 | 72 | if (sig_show == "abc") { 73 | tab.abc = data_box %>% distinct( group, .keep_all = TRUE) 74 | p = p + 75 | geom_text(data=tab.abc, aes(x=group, y=y, color=group, label= stat)) 76 | 77 | p 78 | } 79 | wtq = levels(data$group) 80 | lis = combn(levels(as.factor(data$group)), 2) 81 | x <-lis 82 | my_comparisons <- tapply(x,rep(1:ncol(x),each=nrow(x)),function(i)i) 83 | 84 | line = list() 85 | if (sig_show == "line") { 86 | zuhe = combn(aa$group,2) 87 | xxxx <- tapply(zuhe,rep(1:ncol(zuhe),each=nrow(zuhe)),function(i)i) 88 | xxxx 89 | sig_lis = rep("a",dim(zuhe)[2]) 90 | for (i in 1:dim(zuhe)[2]) { 91 | if (filter(aa, group == xxxx[[i]][1])$groups == filter(aa, group == xxxx[[i]][2])$groups) { 92 | sig_lis[i] = "no_sig" 93 | } 94 | 95 | if (filter(aa, group == xxxx[[i]][1])$groups != filter(aa, group == xxxx[[i]][2])$groups) { 96 | sig_lis[i] = "*" 97 | } 98 | 99 | } 100 | 101 | if (ns == TRUE) { 102 | #-remove the ns 103 | xxxx[as.character((1:length(sig_lis))[sig_lis =="no_sig"])] = NULL 104 | sig_lis = sig_lis[sig_lis != "no_sig"] 105 | } 106 | 107 | line = list(comparisons = xxxx,annotations=sig_lis,y_position = (seq(from=1, to=max(data_box$dd)/4,length.out=dim(zuhe)[2]) + max(data_box$dd)),tip_length = rep(0.03,dim(zuhe)[2])) 108 | p = p + 109 | ggsignif::geom_signif(comparisons = xxxx, annotations=sig_lis, 110 | y_position = (seq(from=1, to=max(data_box$dd)/4,length.out=dim(zuhe)[2]) + max(data_box$dd)), tip_length = rep(0.03,dim(zuhe)[2]),color = "black") 111 | p 112 | } 113 | 114 | p 115 | 116 | return(list(p,data_box)) 117 | } 118 | -------------------------------------------------------------------------------- /R/FacetMuiPlotReBoxBar.R: -------------------------------------------------------------------------------- 1 | #' Use facets to show the results of variance analysis, box+bar plot selected 2 | #' 3 | #' @param data a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection. 4 | #' @param num col index wtich need to test 5 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 6 | #' @param sig_show Distinctive display, "abc" or "line" 7 | #' @param ncol If you choose faceted display, choose to place several graphics per line 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 11 | #' result1 = FacetMuiPlotReBoxBar (data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 12 | #' result1[[1]] 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | 23 | 24 | 25 | 26 | 27 | FacetMuiPlotReBoxBar = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 3 ,fac.level = NULL){ 28 | 29 | for (N in num) { 30 | 31 | name = colnames(data[N]) 32 | 33 | as = result[match( name,colnames(result))] 34 | # as = result[c(N - length(num))] 35 | as 36 | colnames(as) = "groups" 37 | as$group = row.names(as) 38 | 39 | PlotresultBox = aovMuiBoxP(data = data, i= N,sig_show =sig_show,result =as) 40 | 41 | p = PlotresultBox[[2]] 42 | p 43 | name = colnames(data[N]) 44 | p$name = name 45 | 46 | if (N == num[1]) { 47 | A = p 48 | } 49 | if (N != num[1]) { 50 | A = rbind(A,p) 51 | } 52 | 53 | 54 | } 55 | 56 | iris_groups<- dplyr::group_by(A, group,name) 57 | databar<- dplyr::summarise(iris_groups, mean(dd), sd(dd)) 58 | colnames(databar) = c("group","name","mean","sd") 59 | 60 | if (!is.null(fac.level)) { 61 | A$name = factor(A$name,levels = fac.level) 62 | } 63 | 64 | p = ggplot(A) + 65 | geom_bar(data = databar,aes(x= group,y = mean,fill = group),stat = "identity", position = "dodge") + 66 | geom_text(data=A, aes(x=group , y=y ,label=stat))+ 67 | geom_errorbar(data = databar,aes(x= group,y = mean,ymin=mean -sd, ymax=mean +sd),colour="black",width=0.1)+ 68 | geom_jitter(aes(x=group, y=dd, fill=group),A,position=position_jitter(0.17), alpha=0.7,pch = 21,color = "black")+ 69 | labs(x="", y="")+ 70 | facet_wrap(.~name,scales="free_y",ncol = ncol) + 71 | guides(color = FALSE) 72 | 73 | return(list(p,table = A,bartable = databar)) 74 | } 75 | -------------------------------------------------------------------------------- /R/FacetMuiPlotresultBar.R: -------------------------------------------------------------------------------- 1 | #' Use facets to show the results of variance analysis, bar plot selected 2 | #' 3 | #' @param data a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection. 4 | #' @param num col index wtich need to test 5 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 6 | #' @param sig_show Distinctive display, "abc" or "line" 7 | #' @param ncol If you choose faceted display, choose to place several graphics per line 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 11 | #' result1 = FacetMuiPlotresultBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 12 | #' result1[[1]] 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | 23 | 24 | 25 | FacetMuiPlotresultBar = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 3, 26 | fac.level = NULL ){ 27 | N = num[1] 28 | name = colnames(data[N]) 29 | 30 | as = result[match( name,colnames(result))] 31 | colnames(as) = "groups" 32 | as$group = row.names(as) 33 | 34 | PlotresultBar = aovMuiBarPlot(data = data, i= N,sig_show =sig_show,result = as) 35 | 36 | p = PlotresultBar[[2]] 37 | p 38 | name = colnames(data[N]) 39 | p$name = name 40 | A = p 41 | 42 | for (N in num[-1]) { 43 | 44 | name = colnames(data[N]) 45 | 46 | as = result[match( name,colnames(result))] 47 | colnames(as) = "groups" 48 | as$group = row.names(as) 49 | 50 | PlotresultBox = aovMuiBarPlot(data = data, i= N,sig_show =sig_show,result = as) 51 | 52 | p = PlotresultBox[[2]] 53 | p 54 | name = colnames(data[N]) 55 | p$name = name 56 | 57 | A = rbind(A,p) 58 | } 59 | # head(A) 60 | 61 | # a = max(A$SD)*1.2 62 | if (!is.null(fac.level)) { 63 | A$name = factor(A$name,levels = fac.level) 64 | } 65 | p<-ggplot(A, aes(x=group , y=mean ))+ 66 | geom_bar(aes(fill = group),stat = "identity", width = 0.4,position = "dodge") + 67 | geom_bar(data = A, aes(x=1 , y= (mean + SD)*1.1),stat = "identity", width = 0.4,position = "dodge",alpha = 0) + 68 | geom_errorbar(aes(ymin=mean - SD, 69 | ymax=mean+SD), 70 | colour="black",width=0.1,size = 1)+ 71 | 72 | scale_y_continuous(expand = c(0,0))+# 73 | labs( 74 | # x=paste(name_i,"of all group", sep = "_"), 75 | # y=name_i 76 | # title = paste("Normality test",p1,"Homogeneity of variance",p2,sep = ":") 77 | ) + 78 | geom_text(data=A, aes(x=group, y=mean + SD,label=groups),vjust = -1)+ 79 | guides(color=guide_legend(title = NULL),shape=guide_legend(title = NULL)) + facet_wrap(.~name,scales="free_y",ncol = ncol) 80 | 81 | p 82 | if (length(unique(data$group))>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 83 | p 84 | 85 | 86 | return(list(p,table = A)) 87 | } 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /R/FacetMuiPlotresultBox.R: -------------------------------------------------------------------------------- 1 | #' Use facets to show the results of variance analysis, box plot selected 2 | #' 3 | #' @param data a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection. 4 | #' @param num col index wtich need to test 5 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 6 | #' @param sig_show Distinctive display, "abc" or "line" 7 | #' @param ncol If you choose faceted display, choose to place several graphics per line 8 | #' @param loc cahnge the label of "abc" to Suitable location 9 | #' @examples 10 | #' # data(data_wt) 11 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 12 | #' result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 13 | #' result1[[1]] 14 | #' @return list 15 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 16 | #' @references 17 | #' 18 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 19 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 20 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 21 | #' @export 22 | 23 | FacetMuiPlotresultBox = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 3,fac.level = NULL ){ 24 | for (N in num) { 25 | 26 | name = colnames(data[N]) 27 | 28 | as = result[match( name,colnames(result))] 29 | # as = result[c(N - length(num))] 30 | as 31 | colnames(as) = "groups" 32 | as$group = row.names(as) 33 | 34 | PlotresultBox = aovMuiBoxP(data = data, i= N,sig_show =sig_show,result =as) 35 | PlotresultBox[[1]] 36 | p = PlotresultBox[[2]] 37 | p 38 | name = colnames(data[N]) 39 | p$name = name 40 | 41 | if (N == num[1]) { 42 | A = p 43 | } 44 | if (N != num[1]) { 45 | A = rbind(A,p) 46 | } 47 | 48 | } 49 | 50 | if (!is.null(fac.level)) { 51 | A$name = factor(A$name,levels = fac.level) 52 | } 53 | p<-ggplot(A, aes(x=group , y=dd ))+ geom_boxplot(alpha=1, aes(fill=group)) + 54 | geom_jitter( position=position_jitter(0.17), size=0.1, alpha=0.5)+ 55 | labs(x="", y="")+ 56 | # theme_classic()+ 57 | geom_text(data=A, aes(x=group , y=y ,label=stat))+ 58 | #scale_colour_manual(values = mi)+ 59 | #scale_fill_manual(values = mi)+ 60 | #labs(title = "toamto hea and dis")+ 61 | guides(color=guide_legend(title = NULL),shape=guide_legend(title = NULL))+facet_wrap(.~name,scales="free_y",ncol = ncol) 62 | p 63 | 64 | return(list(p,table = A)) 65 | } 66 | -------------------------------------------------------------------------------- /R/FacetMuiPlotresultBox2.R: -------------------------------------------------------------------------------- 1 | #' Use facets to show the results of variance analysis, box plot selected 2 | #' 3 | #' @param data a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection. 4 | #' @param num col index wtich need to test 5 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 6 | #' @param sig_show Distinctive display, "abc" or "line" 7 | #' @param ncol If you choose faceted display, choose to place several graphics per line 8 | #' @param loc cahnge the label of "abc" to Suitable location 9 | #' @examples 10 | #' # data(data_wt) 11 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 12 | #' result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 13 | #' result1[[1]] 14 | #' @return list 15 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 16 | #' @references 17 | #' 18 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 19 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 20 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 21 | #' @export 22 | 23 | FacetMuiPlotresultBox2 = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 3,fac.level = NULL ){ 24 | for (N in num) { 25 | 26 | name = colnames(data[N]) 27 | 28 | as = result[match( name,colnames(result))] 29 | # as = result[c(N - length(num))] 30 | as 31 | colnames(as) = "groups" 32 | as$group = row.names(as) 33 | 34 | PlotresultBox = aovMuiBoxP2(data = data, i= N,sig_show =sig_show,result =as) 35 | PlotresultBox[[1]] 36 | p = PlotresultBox[[2]] 37 | p 38 | name = colnames(data[N]) 39 | p$name = name 40 | 41 | if (N == num[1]) { 42 | A = p 43 | } 44 | if (N != num[1]) { 45 | A = rbind(A,p) 46 | } 47 | 48 | } 49 | 50 | if (!is.null(fac.level)) { 51 | A$name = factor(A$name,levels = fac.level) 52 | } 53 | p<-ggplot(A, aes(x=group , y=dd ))+ geom_boxplot(alpha=1, aes(fill=group)) + 54 | geom_jitter( position=position_jitter(0.17), size=0.1, alpha=0.5)+ 55 | labs(x="", y="")+ 56 | # theme_classic()+ 57 | geom_text(data=A, aes(x=group , y=y ,label=stat))+ 58 | #scale_colour_manual(values = mi)+ 59 | #scale_fill_manual(values = mi)+ 60 | #labs(title = "toamto hea and dis")+ 61 | guides(color=guide_legend(title = NULL),shape=guide_legend(title = NULL))+facet_wrap(.~name,scales="free_y",ncol = ncol) 62 | p 63 | 64 | p <- ggpubr::ggpaired(A, x = "group", y = "dd",id="pid", 65 | color = "group", palette = "lancet", point.size=2,linetype=2, 66 | line.color = "gray", outlier.size=0, size=0.7, width=0.5, fill="transparent", 67 | short.panel.labs = FALSE) + 68 | labs(x="", y="")+ 69 | # theme_classic()+ 70 | geom_text(data=A, aes(x=group , y=y ,label=stat))+ 71 | #scale_colour_manual(values = mi)+ 72 | #scale_fill_manual(values = mi)+ 73 | #labs(title = "toamto hea and dis")+ 74 | 75 | facet_wrap(.~name,scales="free_y",ncol = ncol) 76 | 77 | 78 | 79 | 80 | 81 | return(list(p,table = A)) 82 | } 83 | -------------------------------------------------------------------------------- /R/GroupBar.R: -------------------------------------------------------------------------------- 1 | #' Variance test or non-parametric test results visualization, using boxbar 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num index col which need plot 5 | #' @param sig_show Distinctive display, "abc" or we could find in the future 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param ylimit Adjust the y-axis coordinate range 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 11 | #' result = GroupBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 12 | #' # output result 13 | #' result[[1]] 14 | #' 15 | #' @return list 16 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 17 | #' @references 18 | #' 19 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 20 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 21 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 22 | #' @export 23 | 24 | GroupBar = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ylimit = 1.2 ){ 25 | 26 | N = num[1] 27 | name = colnames(data[N]) 28 | as = result[match( name,colnames(result))] 29 | colnames(as) = "groups" 30 | as$group = row.names(as) 31 | PlotresultBar = aovMuiBarPlot(data = data, i= N,sig_show =sig_show,result = as) 32 | p = PlotresultBar[[2]] 33 | p 34 | name = colnames(data[N]) 35 | p$name = name 36 | A = p 37 | for (N in num[-1]) { 38 | 39 | name = colnames(data[N]) 40 | 41 | as = result[match( name,colnames(result))] 42 | colnames(as) = "groups" 43 | as$group = row.names(as) 44 | 45 | PlotresultBox = aovMuiBarPlot(data = data, i= N,sig_show =sig_show,result = as) 46 | 47 | p = PlotresultBox[[2]] 48 | p 49 | name = colnames(data[N]) 50 | p$name = name 51 | 52 | A = rbind(A,p) 53 | } 54 | 55 | a = max((A$mean +A$SD )) *ylimit 56 | 57 | p<-ggplot(A, aes(x=group , y=mean,group = name ))+ 58 | geom_bar(aes(colour= name,fill = name),stat = "identity", width = 0.9,position = "dodge") + 59 | 60 | geom_errorbar(aes(ymin=mean - SD, 61 | ymax=mean + SD,group = name), 62 | colour="black",width=0.1,size = 1,position = position_dodge(.9))+ 63 | 64 | scale_y_continuous(expand = c(0,0),limits = c(0,a))+#,limits = c(0,a) 65 | labs( 66 | y="count" 67 | # y=name_i 68 | # title = paste("Normality test",p1,"Homogeneity of variance",p2,sep = ":") 69 | ) + 70 | geom_text(data=A, aes(x=group, y=mean +SD ,label=groups),position = position_dodge(.9),vjust = -1)+ 71 | guides(color=guide_legend(title = NULL),shape=guide_legend(title = NULL)) 72 | p 73 | 74 | # p=p+Mytheme 75 | p 76 | 77 | if (length(unique(data$group))>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 78 | p 79 | 80 | 81 | return(list(p,table = A)) 82 | } 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /R/KwWlx.R: -------------------------------------------------------------------------------- 1 | #' Easy for Non-parametric test 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param method wilcox.test or t.test could be seleced. 6 | #' @examples 7 | #' # data(data_wt) 8 | #' result = KwWlx(data = data_wt, i= 4) 9 | #' result[[1]] 10 | #' @return list with two data frame 11 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 12 | #' @references 13 | #' 14 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 15 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 16 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 17 | #' @export 18 | 19 | 20 | #-------------------------------------------Non-parametric test------------------------------- 21 | KwWlx = function(data = data_wt, i= 3,method = "wilcox.test"){ 22 | 23 | ss <- data %>% 24 | dplyr::select("group",count = i) 25 | 26 | # kruskal.test 27 | krusk = ggpubr::compare_means(count ~ group, data=ss, method = "kruskal.test") 28 | # krusk = kruskal.test(count ~ group, data=ss) 29 | 30 | sumkrusk=as.data.frame(krusk) 31 | sumkrusk 32 | #<0.05,It shows that there are differences between multiple groups, you can conduct pairwise non-parametric tests, and mark the letters 33 | krusk <- ggpubr::compare_means(count ~ group, data=ss, method = method) 34 | xx=as.data.frame(krusk) 35 | 36 | #mean for order 37 | da <- ss %>% 38 | dplyr::group_by(group) %>% 39 | dplyr::summarise( mean = mean(count)) %>% 40 | dplyr::arrange(desc(mean)) %>% 41 | as.data.frame() 42 | 43 | if (as.character(da$group)[1] %in% xx$group1) { 44 | xx = xx[order(factor(xx$group1,as.character(da$group))),] 45 | wilcox_levels = xx$p 46 | names(wilcox_levels) = paste(xx$group1,xx$group2,sep = "-") 47 | } else { 48 | xx = xx[order(factor(xx$group2,as.character(da$group))),] 49 | wilcox_levels = xx$p 50 | names(wilcox_levels) = paste(xx$group2,xx$group1,sep = "-") 51 | } 52 | 53 | 54 | wilcox.labels <- data.frame(multcompView::multcompLetters(wilcox_levels, threshold = 0.05)['Letters']) 55 | colnames(wilcox.labels) = "groups" 56 | aa = wilcox.labels 57 | aa$group = row.names(aa) 58 | aa 59 | aa =ord_sig(data = aa,ID = "groups") 60 | 61 | 62 | return(list(aa,wilcox = krusk,kruskal = sumkrusk)) 63 | } 64 | -------------------------------------------------------------------------------- /R/KwWlxPair.R: -------------------------------------------------------------------------------- 1 | #' Easy for Non-parametric test 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param method "t.test" or "wilcox.test" could be selected by method 6 | #' @param paired a logical indicating whether you want a paired test. Used in t.test and in wilcox.test. 7 | #' @examples 8 | #' # data(data_wt) 9 | #' result = KwWlx2(data = data_wt, i= 4,method = "t.test",paired = FALSE) 10 | #' result[[1]] 11 | #' @return data frame 12 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 13 | #' @references 14 | #' 15 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 16 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 17 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 18 | #' @export 19 | 20 | 21 | #-------------------------------------------Non-parametric test------------------------------- 22 | KwWlxPair = function(data = data_wt, i= 3,method = "wilcox.test",paired = FALSE){ 23 | # i = 17 24 | ss <- data %>% 25 | dplyr::select("group",count = i) 26 | 27 | # kruskal.test 28 | krusk = ggpubr::compare_means(count ~ group, data=ss, method = "kruskal.test",paired = paired) 29 | # krusk = kruskal.test(count ~ group, data=ss) 30 | 31 | sumkrusk=as.data.frame(krusk) 32 | sumkrusk 33 | #<0.05,It shows that there are differences between multiple groups, you can conduct pairwise non-parametric tests, and mark the letters 34 | krusk <- ggpubr::compare_means(count ~ group, data=ss, method = method) 35 | xx=as.data.frame(krusk) 36 | 37 | #mean for order 38 | da <- ss %>% 39 | dplyr::group_by(group) %>% 40 | dplyr::summarise( mean = mean(count)) %>% 41 | dplyr::arrange(desc(mean)) %>% 42 | as.data.frame() 43 | 44 | if (as.character(da$group)[1] %in% xx$group1) { 45 | xx = xx[order(factor(xx$group1,as.character(da$group))),] 46 | wilcox_levels = xx$p 47 | names(wilcox_levels) = paste(xx$group1,xx$group2,sep = "-") 48 | } else { 49 | xx = xx[order(factor(xx$group2,as.character(da$group))),] 50 | wilcox_levels = xx$p 51 | names(wilcox_levels) = paste(xx$group2,xx$group1,sep = "-") 52 | } 53 | 54 | 55 | wilcox.labels <- data.frame(multcompView::multcompLetters(wilcox_levels, threshold = 0.05)['Letters']) 56 | colnames(wilcox.labels) = "groups" 57 | aa = wilcox.labels 58 | aa$group = row.names(aa) 59 | aa 60 | # aa =ord_sig(data = aa,ID = "groups") 61 | dat <- ss %>% group_by(group) %>% 62 | summarise(mean = mean(count)) %>% 63 | inner_join(as_tibble(aa),by = c("group" = "group")) %>% 64 | arrange(desc(mean)) 65 | tmp.1 <- dat$groups %>% unique() 66 | tmp.2 <- data.frame(ori = sort(tmp.1,decreasing =TRUE),new = sort(tmp.1,decreasing =FALSE)) 67 | i = 1 68 | for (i in 1:nrow(dat)) { 69 | dat[i,3] <- tmp.2$new[match(dat[i,3],tmp.2$ori)] 70 | } 71 | dat$mean = NULL 72 | dat = dat[match(dat$group,aa$group),][,c(2,1)] %>% as.data.frame() 73 | row.names(dat) = dat$group 74 | 75 | return(list(aa,wilcox = krusk,kruskal = sumkrusk)) 76 | } 77 | -------------------------------------------------------------------------------- /R/MuiHeatmapBubplot.R: -------------------------------------------------------------------------------- 1 | #' MuiHeatmapBubplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param errbar add a distinctive label, TRUE or FEASE could be selected 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param sample sample or group 8 | #' @param col_cluster only used for sample = TRUE 9 | #' @param row_cluster only used for sample = TRUE 10 | #' @param label only used for sample = TRUE 11 | #' @examples 12 | #' # data(data_wt) 13 | #'result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 14 | #'res <- MuiHeatmapBubplot(data = data_wt,i = c(4,9,8) ,result = result, 15 | #' sample = TRUE) 16 | #'res[[1]] 17 | #' @return list 18 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} PengHao Xie \email{2019103106@@njau.edu.cn} 19 | #' @references 20 | #' 21 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 22 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 23 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 24 | #' @export 25 | 26 | 27 | MuiHeatmapBubplot = function( 28 | data = data, 29 | i, 30 | result = result, 31 | sample = FALSE, 32 | scale = TRUE, 33 | col_cluster = TRUE, 34 | row_cluster = TRUE, 35 | label = TRUE 36 | ){ 37 | mean = function(x) { 38 | base::mean(x,na.rm = TRUE) 39 | } 40 | i = c(1,2,i) 41 | data <- data[i] 42 | # data[data > 0.3]<-0.3 43 | mat <- data[,c(-1,-2)] #drop gene column as now in rows 44 | if (col_cluster == TRUE) { 45 | row.names(mat) = data$ID 46 | clust <- hclust(dist(mat %>% as.matrix())) # hclust with distance matrix 47 | ggtree_plot <- ggtree::ggtree(clust) 48 | } 49 | if (row_cluster == TRUE) { 50 | v_clust <- hclust(dist(mat %>% as.matrix() %>% t())) 51 | ggtree_plot_col <- ggtree::ggtree(v_clust) + ggtree::layout_dendrogram() 52 | } 53 | 54 | if (label == TRUE) { 55 | map = data[,c(1,2)] 56 | colnames(map)[1] = "ID" 57 | labels= ggplot(map, aes(x = 0, y=ID, fill=group)) + geom_tile() + 58 | scale_fill_brewer(palette = 'Set1',name="Cell Type") + 59 | theme_void() 60 | } 61 | 62 | if (sample == TRUE) { 63 | tem = data[,c(-2)] 64 | colnames(tem)[1] = "id" 65 | 66 | if (scale == TRUE) { 67 | tem.2 = scale((tem[,c(-1)])) %>% 68 | as.data.frame() 69 | tem = cbind(id = tem[,c(1)],tem.2) 70 | } 71 | 72 | pcm = reshape2::melt(tem, id = c("id")) 73 | head(pcm) 74 | # pcm$variable = factor(pcm$variable,levels = map$ID) 75 | # pcm$id = factor(pcm$id,levels = rig$id) 76 | 77 | p1 = ggplot(pcm, aes(y = id, x = variable)) + 78 | # geom_point(aes(size = value,fill = value), alpha = 0.75, shape = 21) + 79 | geom_tile(aes(fill = value))+ 80 | scale_size_continuous(limits = c(0.000001, 100), range = c(2,25), breaks = c(0.1,0.5,1)) + 81 | labs( y= "", x = "", size = "Relative Abundance (%)", fill = "") + 82 | # scale_fill_manual(values = colours, guide = FALSE) + 83 | scale_x_discrete(limits = rev(levels(pcm$variable))) + 84 | scale_y_discrete(position = "right") + 85 | scale_fill_gradientn(colours =colorRampPalette(RColorBrewer::brewer.pal(11,"Spectral")[11:1])(60))+ 86 | theme( 87 | panel.background=element_blank(), 88 | panel.grid=element_blank(), 89 | axis.text.x = element_text(colour = "black",angle = 90,hjust = 1, 90 | vjust = 0) 91 | 92 | ) 93 | 94 | #----样本在y轴上 95 | p2 = ggplot(pcm, aes(y = id, x = variable)) + 96 | geom_point(aes(size = value,fill = value), alpha = 0.75, shape = 21) + 97 | scale_size_continuous(limits = c(0.000001, 100), range = c(2,25), breaks = c(0.1,0.5,1)) + 98 | labs( y= "", x = "", size = "Relative Abundance (%)", fill = "") + 99 | # scale_fill_manual(values = colours, guide = FALSE) + 100 | scale_x_discrete(limits = rev(levels(pcm$variable))) + 101 | scale_y_discrete(position = "right") + 102 | scale_fill_gradientn(colours =colorRampPalette(RColorBrewer::brewer.pal(11,"Spectral")[11:1])(60)) + 103 | theme( 104 | panel.background=element_blank(), 105 | panel.grid=element_blank(), 106 | axis.text.x = element_text(colour = "black",angle = 90,hjust = 1, 107 | vjust = 0) 108 | 109 | ) 110 | 111 | if (label == T) { 112 | p1 <- p1 %>% 113 | aplot::insert_left(labels, width=.05) 114 | p2 <- p2 %>% 115 | aplot::insert_left(labels, width=.05) 116 | } 117 | 118 | 119 | if (col_cluster == T) { 120 | p1 <- p1 %>% 121 | aplot::insert_left(ggtree_plot, width=.2) 122 | p2 <- p2 %>% 123 | aplot::insert_left(ggtree_plot, width=.2) 124 | } 125 | 126 | 127 | 128 | if (row_cluster == T) { 129 | p1 <- p1 %>% 130 | aplot::insert_top(ggtree_plot_col, height=.2) 131 | p2 <- p2 %>% 132 | aplot::insert_top(ggtree_plot_col, height=.2) 133 | } 134 | 135 | dat = pcm 136 | } else { 137 | tem = data[,c(-1)] 138 | colnames(tem)[1] = "id" 139 | 140 | if (scale == TRUE) { 141 | tem.2 = scale((tem[,c(-1)])) %>% 142 | as.data.frame() 143 | tem = cbind(id = tem[,c(1)],tem.2) 144 | } 145 | 146 | result$group = row.names(result) 147 | abc <- reshape2::melt(result, id="group", variable.name="variable", value.name = "abc") 148 | colnames(abc)[1] = "id" 149 | tem.2 = tem %>% dplyr::group_by(id) %>% 150 | dplyr::summarise_if(is.numeric, mean) %>% 151 | as.data.frame() 152 | 153 | pcm = reshape2::melt(tem.2, id = c("id")) 154 | head(abc) 155 | 156 | dat = pcm %>% dplyr::left_join(abc) 157 | 158 | p1 = ggplot(dat, aes(x = id, y = variable)) + 159 | # geom_point(aes(size = value,fill = value), alpha = 0.75, shape = 21) + 160 | geom_tile(aes(fill = value)) + 161 | geom_text(aes(label = abc)) + 162 | scale_fill_gradientn(colours =colorRampPalette(RColorBrewer::brewer.pal(11,"Spectral")[11:1])(60))+ 163 | theme( 164 | panel.background=element_blank(), 165 | panel.grid=element_blank(), 166 | axis.text.x = element_text(colour = "black",angle = 90) 167 | ) 168 | 169 | #----样本在y轴上 170 | p2 = ggplot(dat, aes(x = id, y = variable)) + 171 | geom_point(aes(size = value,fill = value), alpha = 0.75, shape = 21) + 172 | geom_text(aes(label = abc)) + 173 | scale_size_continuous(limits = c(0.000001, 100), range = c(2,25), breaks = c(0.1,0.5,1)) + 174 | labs( y= "", x = "", size = "Relative Abundance (%)", fill = "") + 175 | # scale_y_discrete(position = "right") + 176 | scale_fill_gradientn(colours =colorRampPalette(RColorBrewer::brewer.pal(11,"Spectral")[11:1])(60)) + 177 | theme( 178 | panel.background=element_blank(), 179 | panel.grid=element_blank(), 180 | axis.text.x = element_text(colour = "black",angle = 90) 181 | 182 | ) 183 | 184 | 185 | } 186 | return(list(p1,p2,dat)) 187 | } 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | -------------------------------------------------------------------------------- /R/MuiKwWlx.R: -------------------------------------------------------------------------------- 1 | #' Multi-group data for non-parametric test 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num index col which need plot 5 | #' @examples 6 | #' # data(data_wt) 7 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 8 | #' result 9 | #' @return data frame 10 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 11 | #' @references 12 | #' 13 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 14 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 15 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 16 | #' @export 17 | 18 | 19 | #Multi-group data for non-parametric test 20 | MuiKwWlx = function(data = data_wt,num = c(4:6)){ 21 | N = num[1] 22 | 23 | data_wt = data 24 | result = KwWlx(data = data_wt, i= N) 25 | aa = result[[1]] 26 | name = colnames(data_wt[N]) 27 | 28 | colnames(aa)[1] = name 29 | aa$group = NULL 30 | A = aa 31 | 32 | for (N in num[-1]) { 33 | result = KwWlx(data = data_wt, i= N) 34 | aa = result[[1]] 35 | name = colnames(data_wt[N]) 36 | 37 | colnames(aa)[1] = name 38 | aa$group = NULL 39 | 40 | A <- cbind(A,aa) 41 | 42 | } 43 | 44 | return(A) 45 | 46 | } 47 | -------------------------------------------------------------------------------- /R/MuiKwWlxPair.R: -------------------------------------------------------------------------------- 1 | #' Multi-group data for non-parametric test paired show... 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num index col which need plot 5 | #' @examples 6 | #' # data(data_wt) 7 | #' result = MuiKwWlxPair(data = data_wt,num = c(4:6)) 8 | #' result 9 | #' @return data frame 10 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 11 | #' @references 12 | #' 13 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 14 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 15 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 16 | #' @export 17 | 18 | 19 | #Multi-group data for non-parametric test 20 | MuiKwWlxPair = function(data = data_wt,num = c(4:6)){ 21 | N = num[1] 22 | data_wt = data 23 | result = KwWlxPair(data = data_wt, i= N,paired = TRUE) 24 | aa = result[[1]] 25 | name = colnames(data_wt[N]) 26 | 27 | colnames(aa)[1] = name 28 | aa$group = NULL 29 | A = aa 30 | 31 | for (N in num[-1]) { 32 | result = KwWlxPair(data = data_wt, i= N,paired = TRUE) 33 | aa = result[[1]] 34 | name = colnames(data_wt[N]) 35 | 36 | colnames(aa)[1] = name 37 | aa$group = NULL 38 | 39 | A <- cbind(A,aa) 40 | 41 | } 42 | 43 | return(A) 44 | 45 | } 46 | -------------------------------------------------------------------------------- /R/MuiNorCV.R: -------------------------------------------------------------------------------- 1 | #' Test normality and homogeneity of variance of inputmore sets of data 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num index col which to test normality and homogeneity 5 | #' @param method_cv which method to test variance, included "leveneTest","bartlett.test". 6 | #' @examples 7 | #' # data(data_wt) 8 | #' norCv = MuiNorCV(data = data_wt,num = c(4,5,6),method_cv = "leveneTest") 9 | #' norCv 10 | #' @return data frame 11 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 12 | #' @references 13 | #' 14 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 15 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 16 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 17 | #' @export 18 | 19 | # # 使用案例 20 | # norCv = MuiNorCV(data = data_wt,num = c(4,5,6),method_cv = "leveneTest") 21 | # norCv 22 | 23 | 24 | ## ---------------------第一部分----------------多组数据正态分布和方差齐性分析 25 | # num = c(4,6) 26 | # N =4 27 | MuiNorCV = function(data = data_wt,num = c(4:6),method_cv = "leveneTest"){ 28 | data_wt = data 29 | s1 = rep("A",length(num)) 30 | s2 = rep("A",length(num)) 31 | s0 = rep("A",length(num)) 32 | i = 1 33 | for (N in num) { 34 | 35 | resul = NorNorCVTest(data = data_wt, i= N ,method_cv = "leveneTest") 36 | a = resul[[1]] 37 | b = resul[[2]] 38 | name = colnames(data_wt[N]) 39 | a1 = length(a$p.value[-dim(a)[1]][!a$p.value[-dim(a)[1]] >= 0.05]) == 0 40 | b1 = b >=.05 41 | s1[i] = a1 42 | s2[i] = b1 43 | s0[i] = name 44 | i = i+1 45 | } 46 | 47 | result = cbind(s0,s1,s2) 48 | colnames(result) = c("DI","cor","CV") 49 | return(result) 50 | 51 | } 52 | -------------------------------------------------------------------------------- /R/MuiPlotFlowBar.R: -------------------------------------------------------------------------------- 1 | #' Stacked histograms add error bars, marked by significance 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param errbar add a distinctive label, TRUE or FEASE could be selected 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param add_abc add sig abc T or F 8 | #' @param order order with colnames according to value 9 | #' @param sample T or F show sample data not group data 10 | #' @examples 11 | #' # data(data_wt) 12 | #' result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 13 | #' res <- MuiPlotFlowBar(data = data_wt,i = c(4,9,8) ,result = result) 14 | #' # utput result 15 | #' res[[1]] 16 | #' @return list 17 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} PengHao Xie \email{2019103106@@njau.edu.cn} 18 | #' @references 19 | #' 20 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 21 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 22 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 23 | #' @export 24 | 25 | 26 | 27 | 28 | MuiPlotFlowBar <- function(data = data, 29 | i, 30 | result = result, 31 | errbar = TRUE, 32 | add_abc = TRUE, 33 | order = FALSE, 34 | sample = FALSE, 35 | flow = F, 36 | ...){ 37 | 38 | #-- data prepare 39 | i = c(2,i) 40 | data <- data[i] 41 | if (order == TRUE) { 42 | tem = colSums(data[,-1]) %>% 43 | as.data.frame() 44 | colnames(tem) = "sum" 45 | id = tem %>% 46 | dplyr::arrange(sum) %>% 47 | row.names() 48 | data= cbind(group = data[,1],data[,-1][,c(match(id,colnames(data[,-1])))]) 49 | } 50 | if (sample == TRUE) { 51 | data$group = row.names(data) 52 | df <- reshape2::melt(data, id="group", variable.name="variable", value.name = "Size") 53 | colnames(df) = c("Sample","Rank","Relative_abundance") 54 | head(df) 55 | p <- ggplot(df, aes(x= Sample, y= Relative_abundance, fill=Rank)) + 56 | geom_bar(stat="identity",color="black", width=.6) 57 | plotdata = df 58 | 59 | 60 | 61 | } else { 62 | result$group = row.names(result) 63 | abc <- reshape2::melt(result, id="group", variable.name="variable", value.name = "abc") 64 | 65 | # data for plot 66 | df <- reshape2::melt(data, id="group", variable.name="variable", value.name = "Size") 67 | head(df) 68 | ## Data statistics mean, standard deviation, standard error 69 | mean <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=mean) 70 | sd <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=sd) 71 | len <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=length) 72 | df_res <- data.frame(mean, sd=sd$x, len=len$x) 73 | colnames(df_res) = c("group", "variable", "Mean", "Sd", "Count") 74 | df_res$Se <- df_res$Sd/sqrt(df_res$Count) 75 | levels(df_res $variable) = as.character(unique(df_res$variable)) 76 | 77 | # Construct error line coordinates-- 78 | # df_res = plyr::ddply(df_res,"group",transform,label_y = cumsum(Mean)) 79 | # Construct distinctive marker positions 80 | df_res_sub = plyr::ddply(df_res,"group", summarize,label_y = cumsum(Mean), label_abc = cumsum(Mean) - 0.5*Mean, 81 | variable = variable) 82 | # df_res = cbind(df_res,df_res_sub[-1]) 83 | df_res <- df_res%>% 84 | dplyr::inner_join(df_res_sub ) 85 | # Factor rearrangement 86 | df_res$variable = factor(df_res$variable,order = F, 87 | levels = levels(df_res$variable)[length(levels(df_res$variable)):1]) 88 | #--conbind plot data 89 | plotdata <- df_res %>% 90 | dplyr::left_join(abc,by = c("group","variable")) 91 | 92 | plotdata$variable = factor(plotdata$variable, 93 | levels = as.character(unique(df_res$variable))[length(levels(df_res$variable)):1]) 94 | 95 | cs = plotdata$variable 96 | lengthfactor <- plotdata$variable %>% 97 | levels() %>% 98 | length() 99 | cs4 <- cs %>% 100 | as.factor() %>% 101 | summary() %>% 102 | as.data.frame() 103 | cs4$id = row.names(cs4) 104 | 105 | 106 | df_arrange<- dplyr::arrange(cs4, id) 107 | Taxonomies_x1<- dplyr::arrange(plotdata , variable) 108 | Taxonomies_x1$ID = factor(rep(c(1:lengthfactor), cs4$.)) 109 | 110 | if (flow) { 111 | # flower plot 112 | p <- ggplot(Taxonomies_x1, 113 | aes(x = group, alluvium = variable, y = Mean)) + 114 | ggalluvial::geom_flow(aes(fill = variable, colour = variable), width = 0) 115 | 116 | }else { 117 | p <- ggplot(Taxonomies_x1, aes(x = group, y = Mean,fill = variable, 118 | alluvium = variable,stratum = ID)) + 119 | ggalluvial::geom_flow(aes(fill = variable, colour = aa), 120 | stat = "alluvium", lode.guidance = "rightleft", 121 | color = "black",size = 0.2,width = 0.35,alpha = .2) + 122 | geom_bar(width = 0.45,stat = "identity") 123 | } 124 | 125 | if (add_abc == TRUE) { 126 | p = p + 127 | geom_text(aes(y = label_abc, label = abc)) 128 | } 129 | 130 | 131 | if (errbar == TRUE) { 132 | p <- p + geom_errorbar(aes(ymin=label_y-Sd, ymax=label_y +Sd), width=.2) 133 | } 134 | 135 | } 136 | # id = plotdata %>% 137 | # dplyr::group_by(variable) %>% 138 | # dplyr::summarise(mean(Mean)) %>% 139 | # dplyr::arrange(`mean(Mean)`) %>% 140 | # .$variable 141 | # plotdata$variable = factor(as.character(plotdata$variable), 142 | # levels = as.character(id)) 143 | 144 | 145 | return(list(p,plotdata)) 146 | } 147 | 148 | -------------------------------------------------------------------------------- /R/MuiPlotReBoxBar.R: -------------------------------------------------------------------------------- 1 | #' Visualize multiple sets of data Scatter plot + barplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param path creat a folder to save the single plot. 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' MuiPlotReBoxBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 12 | #' 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | MuiPlotReBoxBar = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",path = "./MuiboxBar/"){ 23 | dir.create(path) 24 | data = data 25 | Mytheme <- theme_bw()+ 26 | 27 | # scale_fill_manual(values = mi, guide = guide_legend(title = NULL))+ 28 | theme( 29 | 30 | panel.grid.major=element_blank(), 31 | panel.grid.minor=element_blank(), 32 | 33 | plot.title = element_text(vjust = -8.5,hjust = 0.1), 34 | axis.title.y =element_text(size = 20,face = "bold",colour = "black"), 35 | axis.title.x =element_text(size = 24,face = "bold",colour = "black"), 36 | axis.text = element_text(size = 20,face = "bold"), 37 | axis.text.x = element_text(colour = "black",size = 14), 38 | axis.text.y = element_text(colour = "black",size = 14), 39 | legend.text = element_text(size = 15,face = "bold"), 40 | legend.position = "none"#是否删除图例 41 | 42 | ) 43 | # N = 3 44 | 45 | for (N in num) { 46 | name = colnames(data[N]) 47 | 48 | as = result[match( name,colnames(result))] 49 | as 50 | colnames(as) = "groups" 51 | as$group = row.names(as) 52 | 53 | PlotresultBox = aovMuiBoxBarP(data = data, i= N,sig_show =sig_show,result = as) 54 | p = PlotresultBox[[1]] 55 | p 56 | if (dim(as)[1]>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 57 | name = colnames(data[N]) 58 | 59 | path = path 60 | dir.create(path) 61 | FileName <- paste(path,name,"_boxbar", ".pdf", sep = "_") 62 | ggsave(FileName, p, width = 8, height = 8) 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /R/MuiPlotStackBar.R: -------------------------------------------------------------------------------- 1 | #' Stacked histograms add error bars, marked by significance 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param errbar add a distinctive label, TRUE or FEASE could be selected 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param add_abc add sig abc T or F 8 | #' @param order order with colnames according to value 9 | #' @param sample T or F show sample data not group data 10 | #' @examples 11 | #' # data(data_wt) 12 | #' result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 13 | #' res <- MuiPlotStackBar(data = data,i = c(4,9,8) ,result = result) 14 | #' # utput result 15 | #' res[[1]] 16 | #' @return list 17 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} PengHao Xie \email{2019103106@@njau.edu.cn} 18 | #' @references 19 | #' 20 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 21 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 22 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 23 | #' @export 24 | 25 | 26 | MuiPlotStackBar <- function(data = data, 27 | i, 28 | result = result, 29 | errbar = TRUE, 30 | add_abc = TRUE, 31 | order = FALSE, 32 | sample = FALSE, 33 | ...){ 34 | 35 | #-- data prepare 36 | i = c(2,i) 37 | data <- data[i] 38 | if (order == TRUE) { 39 | tem = colSums(data[,-1]) %>% 40 | as.data.frame() 41 | colnames(tem) = "sum" 42 | id = tem %>% 43 | dplyr::arrange(sum) %>% 44 | row.names() 45 | data= cbind(group = data[,1],data[,-1][,c(match(id,colnames(data[,-1])))]) 46 | } 47 | if (sample == TRUE) { 48 | data$group = row.names(data) 49 | df <- reshape2::melt(data, id="group", variable.name="variable", value.name = "Size") 50 | colnames(df) = c("Sample","Rank","Relative_abundance") 51 | head(df) 52 | p <- ggplot(df, aes(x= Sample, y= Relative_abundance, fill=Rank)) + 53 | geom_bar(stat="identity",color="black", width=.6) 54 | plotdata = df 55 | } else { 56 | result$group = row.names(result) 57 | abc <- reshape2::melt(result, id="group", variable.name="variable", value.name = "abc") 58 | 59 | # data for plot 60 | df <- reshape2::melt(data, id="group", variable.name="variable", value.name = "Size") 61 | head(df) 62 | ## Data statistics mean, standard deviation, standard error 63 | mean <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=mean) 64 | sd <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=sd) 65 | len <- stats::aggregate(df$Size, by=list(df$group, df$variable), FUN=length) 66 | df_res <- data.frame(mean, sd=sd$x, len=len$x) 67 | colnames(df_res) = c("group", "variable", "Mean", "Sd", "Count") 68 | df_res$Se <- df_res$Sd/sqrt(df_res$Count) 69 | levels(df_res $variable) = as.character(unique(df_res$variable)) 70 | 71 | # Construct error line coordinates-- 72 | # df_res = plyr::ddply(df_res,"group",transform,label_y = cumsum(Mean)) 73 | # Construct distinctive marker positions 74 | df_res_sub = plyr::ddply(df_res,"group", summarize,label_y = cumsum(Mean), label_abc = cumsum(Mean) - 0.5*Mean, 75 | variable = variable) 76 | # df_res = cbind(df_res,df_res_sub[-1]) 77 | df_res <- df_res%>% 78 | dplyr::inner_join(df_res_sub ) 79 | # Factor rearrangement 80 | df_res$variable = factor(df_res$variable,order = F, 81 | levels = levels(df_res$variable)[length(levels(df_res$variable)):1]) 82 | #--conbind plot data 83 | plotdata <- df_res %>% 84 | dplyr::left_join(abc,by = c("group","variable")) 85 | 86 | plotdata$variable = factor(plotdata$variable, 87 | levels = as.character(unique(df_res$variable))[length(levels(df_res$variable)):1]) 88 | 89 | 90 | ### ggplot ploting 91 | p <- ggplot(plotdata, aes(x= group, y=Mean, fill=variable)) + 92 | geom_bar(stat="identity",color="black", width=.6) 93 | if (add_abc == TRUE) { 94 | p = p + 95 | geom_text(aes(y = label_abc, label = abc)) 96 | } 97 | 98 | if (errbar == TRUE) { 99 | p <- p + geom_errorbar(aes(ymin=label_y-Sd, ymax=label_y +Sd), width=.2) 100 | } 101 | 102 | } 103 | # id = plotdata %>% 104 | # dplyr::group_by(variable) %>% 105 | # dplyr::summarise(mean(Mean)) %>% 106 | # dplyr::arrange(`mean(Mean)`) %>% 107 | # .$variable 108 | # plotdata$variable = factor(as.character(plotdata$variable), 109 | # levels = as.character(id)) 110 | 111 | 112 | return(list(p,plotdata)) 113 | } 114 | 115 | -------------------------------------------------------------------------------- /R/MuiPlotresultBar.R: -------------------------------------------------------------------------------- 1 | #' Visualize multiple sets of data barplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param path creat a folder to save the single plot. 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 11 | #' MuiPlotresultBar(data = data_wt,num = c(4:6),result = result ,sig_show ="line") 12 | #' 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | 23 | 24 | MuiPlotresultBar = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",path = "./Muibar/"){ 25 | dir.create(path) 26 | for (N in num) { 27 | name = colnames(data[N]) 28 | 29 | as = result[match( name,colnames(result))] 30 | colnames(as) = "groups" 31 | as$group = row.names(as) 32 | 33 | PlotresultBar = aovMuiBarPlot(data = data, i= N,sig_show =sig_show,result = as) 34 | p = PlotresultBar[[1]] 35 | name = colnames(data[N]) 36 | p 37 | if (dim(as)[1]>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 38 | path = path 39 | dir.create(path) 40 | FileName <- paste(path,name,"_bar", ".pdf", sep = "_") 41 | ggsave(FileName, p, width = 8, height = 8) 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /R/MuiPlotresultBox.R: -------------------------------------------------------------------------------- 1 | #' Visualize multiple sets of data Scatter plot + boxplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param path creat a folder to save the single plot. 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' MuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 12 | #' 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | 23 | 24 | MuiPlotresultBox = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",path = "./Muibox/" ){ 25 | dir.create(path) 26 | 27 | for (N in num) { 28 | name = colnames(data[N]) 29 | 30 | as = result[match( name,colnames(result))] 31 | as 32 | colnames(as) = "groups" 33 | as$group = row.names(as) 34 | 35 | PlotresultBox = aovMuiBoxP(data = data, i= N,sig_show =sig_show,result = as) 36 | p = PlotresultBox[[1]] 37 | p 38 | if (dim(as)[1]>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 39 | name = colnames(data[N]) 40 | path = path 41 | FileName <- paste(path,name,"_bar", ".pdf", sep = "_") 42 | ggsave(FileName, p, width = 8, height = 8) 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /R/MuiPlotresultBox2.R: -------------------------------------------------------------------------------- 1 | #' Visualize multiple sets of data Scatter plot + boxplot 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num col index wtich need to test 5 | #' @param sig_show Distinctive display, "abc" or "line" 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param path creat a folder to save the single plot. 8 | #' @examples 9 | #' # data(data_wt) 10 | #' result = KwWlx(data = data_wt, i= 4) 11 | #' MuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 12 | #' 13 | #' @return list 14 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 15 | #' @references 16 | #' 17 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 18 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 19 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 20 | #' @export 21 | 22 | 23 | 24 | MuiPlotresultBox = function(data = data_wt,num = c(4:6),result = result,sig_show ="abc",path = "./Muibox/" ){ 25 | dir.create(path) 26 | 27 | for (N in num) { 28 | name = colnames(data[N]) 29 | 30 | as = result[match( name,colnames(result))] 31 | as 32 | colnames(as) = "groups" 33 | as$group = row.names(as) 34 | 35 | PlotresultBox = aovMuiBoxP2(data = data, i= N,sig_show =sig_show,result = as) 36 | p = PlotresultBox[[1]] 37 | p 38 | if (dim(as)[1]>3){ p=p+theme(axis.text.x=element_text(angle=45,vjust=1, hjust=1))} 39 | name = colnames(data[N]) 40 | path = path 41 | FileName <- paste(path,name,"_bar", ".pdf", sep = "_") 42 | ggsave(FileName, p, width = 8, height = 8) 43 | 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /R/MuiStat.R: -------------------------------------------------------------------------------- 1 | #' A complete single-factor difference analysis process for mui col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method. 2 | #' 3 | #' @param data a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection. 4 | #' @param num col index wtich need to test 5 | #' @param method_cv which method to test variance, included "leveneTest","bartlett.test" 6 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 7 | #' @param sig_show Distinctive display, "abc" or "line" 8 | #' @param plot chose the plot type shuld be a barplot or boxplot or bar+box plot 9 | #' @param plottype select a plot type, included "single" and "mui" 10 | #' @param ncol If you choose faceted display, choose to place several graphics per line 11 | #' @param path creat a folder to save the single plot, if you seleted the model "single" 12 | #' @examples 13 | #' # data(data_wt) 14 | #' result = MuiStat(data = data_wt,num = c(4,5,6),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 2,plot = "boxbar",plottype = "mui") 15 | #' result[[1]] 16 | #' @return list 17 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 18 | #' @references 19 | #' 20 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 21 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 22 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 23 | #' @export 24 | 25 | 26 | 27 | MuiStat = function(data = data_wt,num = c(4,5,6),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 2,plot = "bar",plottype = "mui",path = "./output"){ 28 | 29 | norCv = MuiNorCV(data = data,num = num,method_cv = "leveneTest") 30 | 31 | # Divide the group that conforms to the normal distribution and the homogeneity of the variance into one group, 32 | # and divide the group that does not meet the two into a group; 33 | AA = c() 34 | BB = c() 35 | for (i in 1:length(num)) { 36 | 37 | if (norCv[,"cor"][i] == TRUE & norCv[,"CV"][i] == TRUE) { 38 | num[i] 39 | AA = c(AA,num[i]) 40 | AA 41 | 42 | } 43 | 44 | if (norCv[,"cor"][i] == FALSE | norCv[,"CV"][i] == FALSE) { 45 | num[i] 46 | BB = c(BB,num[i]) 47 | BB 48 | 49 | } 50 | 51 | } 52 | 53 | if (!is.null(AA)) { 54 | resultAA = MuiaovMcomper2(data = data,num = AA,method_Mc = method_Mc ) 55 | } else if(is.null(AA)){ 56 | resultAA = NULL 57 | 58 | } 59 | 60 | if(!is.null(BB)){ 61 | resultBB = MuiKwWlx2(data = data,num = BB) 62 | } else if(is.null(BB)){ 63 | resultBB = NULL 64 | 65 | } 66 | 67 | if (!is.null(AA) & !is.null(BB)) { 68 | resultall = cbind(resultAA,resultBB) 69 | } else if (is.null(AA)) { 70 | resultall = cbind(resultBB) 71 | } else if (is.null(BB)) { 72 | resultall = cbind(resultAA) 73 | } 74 | 75 | 76 | 77 | 78 | num = c(AA,BB) 79 | if (plottype == "single") { 80 | if (plot == "bar") { 81 | plot = MuiPlotresultBar(data = data,num = num,result = resultall,sig_show = sig_show,path = path) 82 | p = "Folder" 83 | } 84 | if (plot == "box") { 85 | plot = MuiPlotresultBox(data = data,num = num,result = resultall,sig_show = sig_show,path = path) 86 | p = "Folder" 87 | } 88 | if (plot == "boxbar") { 89 | plot = MuiPlotresultBox(data = data,num = num,result = resultall,sig_show = sig_show,path = path) 90 | p = "Folder" 91 | } 92 | } 93 | if (plottype == "mui") { 94 | if (plot == "bar") { 95 | result1 = FacetMuiPlotresultBar(data = data,num = num,result = resultall,sig_show =sig_show,ncol = ncol ) 96 | p = result1[[1]] 97 | } 98 | if (plot == "box") { 99 | result1 = FacetMuiPlotresultBox(data = data,num = num,result = resultall,sig_show =sig_show,ncol =ncol ) 100 | p = result1[[1]] 101 | } 102 | if (plot == "boxbar") { 103 | result1 = FacetMuiPlotReBoxBar(data = data,num = num,result = resultall,sig_show =sig_show,ncol =ncol ) 104 | p = result1[[1]] 105 | } 106 | } 107 | 108 | return(list(p, aov = AA,wlx = BB,table =resultall )) 109 | 110 | 111 | } 112 | -------------------------------------------------------------------------------- /R/MuiaovMcomper.R: -------------------------------------------------------------------------------- 1 | #' Perform ANOVA and run multiple comparisons for more sets of data 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param num index col which to test normality and homogeneity 5 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 6 | #' @examples 7 | #' # data(data_wt) 8 | #' result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 9 | #' # utput result for multiple comparison results 10 | #' result 11 | #' @return data frame 12 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 13 | #' @references 14 | #' 15 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 16 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 17 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 18 | #' @export 19 | 20 | 21 | 22 | MuiaovMcomper = function(data = data_wt,num = c(4:6),method_Mc = "Tukey"){ 23 | N = num[1] 24 | 25 | result = aovMcomper (data = data, i= N,method_Mc = method_Mc) 26 | aa = result[[1]] 27 | name = colnames(data[N]) 28 | colnames(aa)[1] = name 29 | aa$group = NULL 30 | A = aa 31 | 32 | for (N in num[-1]) { 33 | result = aovMcomper (data = data, i= N,method_Mc = method_Mc) 34 | aa = result[[1]] 35 | name = colnames(data[N]) 36 | 37 | colnames(aa)[1] = name 38 | aa <- aa[match(row.names(A),row.names(aa)),] 39 | aa$group = NULL 40 | A = cbind(A,aa) 41 | } 42 | 43 | return(A) 44 | } 45 | -------------------------------------------------------------------------------- /R/NorNorCVTest.R: -------------------------------------------------------------------------------- 1 | #' Test normality and homogeneity of variance of Input data 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param method_cv which method to test variance, included "leveneTest","bartlett.test". 6 | #' @examples 7 | #' # data(data_wt) 8 | #' NorNorCVTest(data = data_wt, i= 4) 9 | #' @return data frame 10 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 11 | #' @references 12 | #' 13 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 14 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 15 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 16 | #' @export 17 | 18 | 19 | NorNorCVTest = function(data = data_wt, i= 4,method_cv = "leveneTest",...){ 20 | ##----Test normality and homogeneity of variance of Input data------- 21 | ss <- data %>% 22 | dplyr::select("group",count = i) 23 | shapiro.test.multi <- function( 24 | data, 25 | value, 26 | group) 27 | { 28 | table(data[,group]) %>% 29 | data.frame(.) -> a1 30 | a2 <- as.vector(a1[,1]) 31 | data = data.frame(group = data[,group], # 32 | value = data[,value]) # 33 | 34 | test.result <- data.frame(No=0, #row number 35 | Name=0, #group name 36 | W=0, #W value 37 | p.value=0, #p value 38 | norm.test=0) #result 39 | for (i in (1:length(a2))){ 40 | # subgroup for shapiro.text 41 | subset(data, 42 | group == a2[i], 43 | select = value) %>% 44 | .[,1] %>% 45 | shapiro.test(.) -> t.r 46 | test.result[i,1] = i #group number 47 | test.result[i,2] = a2[i] #group name 48 | test.result[i,3] = t.r$statistic #w value 49 | test.result[i,4] = t.r$p.value #p value 50 | if 51 | (t.r$p.value > 0.05) 52 | test.result[i,5] = "Norm" 53 | else 54 | test.result[i,5] = "Other_situation" 55 | } 56 | test.result[nrow( test.result)+1,1] = "Test Method:" # final col add the method of text 57 | test.result[nrow( test.result),2] = "Shapiro-Wilk" #final col two row add the method 58 | return(test.result) 59 | } 60 | a = shapiro.test.multi(data[c(2,i)],value = colnames(data[c(2,i)][2]),group = "group") 61 | a 62 | # selected the method for tast the Homogeneity of variance 63 | # p2 >=.05:Homogeneity of variance 64 | if (method_cv == "leveneTest" ) { 65 | xc <- car::leveneTest(count~group,data=ss) 66 | p2 <- xc[[3]][1] 67 | p2 <- round(p2,3) 68 | } 69 | if (method_cv == "bartlett.test" ) { 70 | xc <- bartlett.test(count~group,data=ss) 71 | p2 <- xc[[3]] 72 | p2 <- round(p2,3) 73 | } 74 | return(list(a,p2)) 75 | } 76 | -------------------------------------------------------------------------------- /R/SingleStat.R: -------------------------------------------------------------------------------- 1 | #' A complete single-factor difference analysis process for single col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method. 2 | #' 3 | #' @param data a data.frame contain the input data.Enter the data frame, the first column is the sample number, 4 | #' the second column is the group, note that the group label must be set to group, and the third column and later are the 5 | #' indicators for measurement or collection. 6 | #' @param num col index wtich need to test 7 | #' @param method_cv which method to test variance, included "leveneTest","bartlett.test" 8 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 9 | #' @param sig_show Distinctive display, "abc" or "line" 10 | #' @examples 11 | #' # data(data_wt) 12 | #' result = SingleStat(data = data_wt,plot = "bar",method_Mc = "Tukey",i= 4,sig_show ="abc") 13 | #' result[[1]] 14 | #' @return list 15 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 16 | #' @references 17 | #' 18 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 19 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 20 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 21 | #' @export 22 | 23 | 24 | SingleStat = function(data = data_wt,plot = "bar",method_Mc = "Tukey",i= 4,sig_show ="abc"){ 25 | 26 | NorCV = NorNorCVTest(data = data, i= i,method_cv = "leveneTest") 27 | # 28 | a = NorCV[[1]] 29 | p1 = length(a$p.value[-dim(a)[1]][!a$p.value[-dim(a)[1]] >= 0.05]) == 0 30 | p2 = NorCV[[2]] 31 | 32 | 33 | if (p1!= 0& p2 >.05) { 34 | result= aovMcomper2 (data = data, i= i,method_Mc = "Tukey") 35 | A = print("aov") 36 | A 37 | } else if (p1 != 0| p2 <.05){ 38 | result = KwWlx2(data = data, i= i) 39 | A = print("wlx") 40 | A 41 | } 42 | 43 | if (plot == "bar") { 44 | PlotresultBar = aovMuiBarPlot(data = data, i= i,sig_show =sig_show,result = result[[1]]) 45 | p = PlotresultBar[[1]] 46 | 47 | } else if (plot == "box"){ 48 | PlotresultBox = aovMuiBoxP2(data = data, i= i,sig_show =sig_show,result = result[[1]]) 49 | p = PlotresultBox[[1]] 50 | 51 | }else if (plot == "boxbar"){ 52 | PlotresultBox = aovMuiBoxBarP(data = data, i= i,sig_show =sig_show,result = result[[1]]) 53 | p = PlotresultBox[[1]] 54 | 55 | } 56 | 57 | return(list(p,table = result[[1]],method =A)) 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /R/aovMcomper.R: -------------------------------------------------------------------------------- 1 | #' Perform ANOVA and run multiple comparisons 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 6 | #' @examples 7 | #' # data(data_wt) 8 | #' result= aovMcomper (data = data_wt, i= 5,method_Mc = "Tukey") 9 | #' # utput result for multiple comparison results 10 | #' result[[1]] 11 | #' @return data frame 12 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 13 | #' @references 14 | #' 15 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 16 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 17 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 18 | #' @export 19 | 20 | 21 | # if (is.numeric(i)) { 22 | # ss <- data %>% 23 | # dplyr::select("group",count = i) 24 | # 25 | # } else if (is.character(i)) { 26 | # ss <- data %>% 27 | # dplyr::select("group",count = i) 28 | # } 29 | 30 | aovMcomper = function( data = data_wt, i= 3,method_Mc = "Tukey"){ 31 | ss <- data %>% 32 | dplyr::select("group",count = i) 33 | 34 | # variance analysis 35 | model<-aov(count ~ group, data= ss) 36 | wtx1 = summary(model) 37 | wtx2 = wtx1[[1]] 38 | wtx3 = wtx2[5]# 39 | # Tukey 40 | if (method_Mc == "Tukey") { 41 | 42 | litter.mc <- multcomp::glht(model, linfct = multcomp::mcp(group = 'Tukey')) 43 | insx = multcomp::cld(litter.mc) 44 | aa <- insx$mcletters$monospacedLetters 45 | aa = as.data.frame(aa) 46 | colnames(aa) = c("groups") 47 | head(aa) 48 | aa$group = row.names(aa) 49 | 50 | } 51 | 52 | # LSD 53 | if (method_Mc == "LSD") { 54 | 55 | out <- agricolae::LSD.test(model,"group", p.adj="none") 56 | aa = out$group# 57 | aa$group = row.names(aa) 58 | aa = aa[2:3] 59 | aa 60 | } 61 | #SNK method (Student-Newman-Keuls)The results are similar to LSD.test. 62 | if (method_Mc == "SNK") { 63 | out <- agricolae::SNK.test(model,"group") 64 | aa = out$groups# View label of each group 65 | 66 | aa$group = row.names(aa) 67 | stat = aa 68 | aa = aa[2:3] 69 | } 70 | 71 | #Duncan 72 | if (method_Mc == "Duncan") { 73 | 74 | out <-agricolae::duncan.test (model,"group") 75 | aa = out$groups# View label of each group 76 | 77 | aa$group = row.names(aa) 78 | stat = aa 79 | aa 80 | aa = aa[2:3] 81 | } 82 | 83 | #Scheffe features:The number of samples in each group is equal or unequal, but it is more used if the number of samples in each group is not equal; 84 | if (method_Mc == "scheffe") { 85 | out <-agricolae::scheffe.test (model,"group") 86 | aa = out$groups# View label of each group 87 | aa$group = row.names(aa) 88 | stat = aa 89 | aa = aa[2:3] 90 | } 91 | # aa =ord_sig(data = aa,ID = "groups") 92 | return(list(Muicomper = aa,model)) 93 | } 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /R/ord_sig.R: -------------------------------------------------------------------------------- 1 | #' Reverse the significance level of letter marks 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param ID col index wtich need to reverse significance level,if NULL was marked, would transform to each col. 5 | #' @examples 6 | #' # data(data_wt) 7 | #' result = KwWlx(data = data_wt, i= 4) 8 | #' datord <- ord_sig(data = result[[1]],ID = NULL) 9 | #' @return data.frame 10 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 11 | #' @references 12 | #' 13 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 14 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 15 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 16 | #' @export 17 | 18 | 19 | 20 | ord_sig <- function(data = da,ID = "groups"){ 21 | if (!is.null(ID)) { 22 | data[,ID] = gsub(" ","",as.character(data[,ID])) 23 | aa <- unique(as.character(data[,ID] )) 24 | 25 | # sort(aa,decreasing =TRUE) 26 | # sort(aa,decreasing =FALSE) 27 | 28 | tmp <- data.frame(ori = sort(aa,decreasing =TRUE),new = sort(aa,decreasing =FALSE)) 29 | 30 | for (i in 1:nrow(data)) { 31 | data[,ID][i] <- as.character(tmp$new[match(data[,ID][i],tmp$ori)]) 32 | 33 | } 34 | 35 | } 36 | 37 | if (is.null(ID)) { 38 | for (i in 1:ncol(data)) { 39 | aa <- unique(as.character(data[,i] )) 40 | tmp <- data.frame(ori = sort(aa,decreasing =TRUE),new = sort(aa,decreasing =FALSE)) 41 | for (ii in 1:nrow(data)) { 42 | data[,i][ii] <- as.character(tmp$new[match(data[,i][ii],tmp$ori)]) 43 | } 44 | } 45 | } 46 | return(data) 47 | 48 | } 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /R/util.R: -------------------------------------------------------------------------------- 1 | #' Perform ANOVA and run multiple comparisons and order in order to mean value of treatment 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 6 | #' @examples 7 | #' # data(data_wt) 8 | #' result= aovMcomper2 (data = data_wt, i= 5,method_Mc = "Tukey") 9 | #' # utput result for multiple comparison results 10 | #' result[[1]] 11 | #' @return data frame 12 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 13 | #' @references 14 | #' 15 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 16 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 17 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 18 | #' @export 19 | 20 | 21 | # if (is.numeric(i)) { 22 | # ss <- data %>% 23 | # dplyr::select("group",count = i) 24 | # 25 | # } else if (is.character(i)) { 26 | # ss <- data %>% 27 | # dplyr::select("group",count = i) 28 | # } 29 | aovMcomper2 = function( data = data_wt, i= 3,method_Mc = "Tukey"){ 30 | ss <- data %>% 31 | dplyr::select("group",count = i) 32 | 33 | # variance analysis 34 | model<-aov(count ~ group, data= ss) 35 | wtx1 = summary(model) 36 | wtx2 = wtx1[[1]] 37 | wtx3 = wtx2[5]# 38 | # Tukey 39 | if (method_Mc == "Tukey") { 40 | 41 | litter.mc <- multcomp::glht(model, linfct = multcomp::mcp(group = 'Tukey')) 42 | insx = multcomp::cld(litter.mc) 43 | aa <- insx$mcletters$monospacedLetters %>% as.data.frame() 44 | colnames(aa) = c("groups") 45 | aa$groups = gsub(" ","",aa$groups) 46 | aa$group = row.names(aa) 47 | 48 | 49 | } 50 | 51 | # LSD 52 | if (method_Mc == "LSD") { 53 | 54 | out <- agricolae::LSD.test(model,"group", p.adj="none") 55 | aa = out$group# 56 | aa$group = row.names(aa) 57 | aa = aa[2:3] 58 | aa 59 | } 60 | #SNK method (Student-Newman-Keuls)The results are similar to LSD.test. 61 | if (method_Mc == "SNK") { 62 | out <- agricolae::SNK.test(model,"group") 63 | aa = out$groups# View label of each group 64 | aa$group = row.names(aa) 65 | stat = aa 66 | aa = aa[2:3] 67 | } 68 | 69 | #Duncan 70 | if (method_Mc == "Duncan") { 71 | 72 | out <-agricolae::duncan.test (model,"group") 73 | aa = out$groups# View label of each group 74 | 75 | aa$group = row.names(aa) 76 | stat = aa 77 | aa = aa[2:3] 78 | } 79 | 80 | #Scheffe features:The number of samples in each group is equal or unequal, but it is more used if the number of samples in each group is not equal; 81 | if (method_Mc == "scheffe") { 82 | out <-agricolae::scheffe.test (model,"group") 83 | aa = out$groups# View label of each group 84 | aa$group = row.names(aa) 85 | stat = aa 86 | aa = aa[2:3] 87 | } 88 | 89 | dat <- ss %>% group_by(group) %>% 90 | dplyr::summarise(mean = mean(count)) %>% 91 | dplyr::inner_join(as_tibble(aa),by = c("group" = "group")) %>% 92 | dplyr::arrange(desc(mean)) 93 | tmp.1 <- dat$groups %>% unique() 94 | tmp.2 <- data.frame(ori = tmp.1,new = sort(tmp.1,decreasing = FALSE)) 95 | i = 1 96 | for (i in 1:nrow(dat)) { 97 | dat[i,3] <- tmp.2$new[match(dat[i,3],tmp.2$ori)] 98 | } 99 | dat$mean = NULL 100 | dat = dat[match(dat$group,aa$group),][,c(2,1)] %>% as.data.frame() 101 | row.names(dat) = dat$group 102 | # aa =ord_sig(data = aa,ID = "groups") 103 | return(list(Muicomper = dat,model)) 104 | } 105 | 106 | #' Easy for Non-parametric test and order in order to mean value of treatment 107 | #' 108 | #' @param data a data.frame contain the input data 109 | #' @param i col index wtich need to test 110 | #' @param method wilcox.test or t.test could be seleced. 111 | #' @examples 112 | #' # data(data_wt) 113 | #' result = KwWlx2(data = data_wt, i= 4) 114 | #' result[[1]] 115 | #' @return list with two data frame 116 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 117 | #' @references 118 | #' 119 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 120 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 121 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 122 | #' @export 123 | 124 | KwWlx2 = function(data = data_wt, i= 3,method = "wilcox.test"){ 125 | 126 | ss <- data %>% 127 | dplyr::select("group",count = i) 128 | 129 | # kruskal.test 130 | krusk = ggpubr::compare_means(count ~ group, data=ss, method = "kruskal.test") 131 | # krusk = kruskal.test(count ~ group, data=ss) 132 | 133 | sumkrusk=as.data.frame(krusk) 134 | sumkrusk 135 | #<0.05,It shows that there are differences between multiple groups, you can conduct pairwise non-parametric tests, and mark the letters 136 | krusk <- ggpubr::compare_means(count ~ group, data=ss, method = method) 137 | xx=as.data.frame(krusk) 138 | 139 | #mean for order 140 | da <- ss %>% 141 | dplyr::group_by(group) %>% 142 | dplyr::summarise( mean = mean(count)) %>% 143 | dplyr::arrange(desc(mean)) %>% 144 | as.data.frame() 145 | 146 | if (as.character(da$group)[1] %in% xx$group1) { 147 | xx = xx[order(factor(xx$group1,as.character(da$group))),] 148 | wilcox_levels = xx$p 149 | names(wilcox_levels) = paste(xx$group1,xx$group2,sep = "-") 150 | } else { 151 | xx = xx[order(factor(xx$group2,as.character(da$group))),] 152 | wilcox_levels = xx$p 153 | names(wilcox_levels) = paste(xx$group2,xx$group1,sep = "-") 154 | } 155 | 156 | 157 | wilcox.labels <- data.frame(multcompView::multcompLetters(wilcox_levels, threshold = 0.05)['Letters']) 158 | colnames(wilcox.labels) = "groups" 159 | aa = wilcox.labels 160 | aa$group = row.names(aa) 161 | # aa =ord_sig(data = aa,ID = "groups") 162 | dat <- ss %>% group_by(group) %>% 163 | dplyr::summarise(mean = mean(count)) %>% 164 | dplyr::inner_join(as_tibble(aa),by = c("group" = "group")) %>% 165 | dplyr::arrange(desc(mean)) 166 | tmp.1 <- dat$groups %>% unique() 167 | tmp.2 <- data.frame(ori = tmp.1,new = sort(tmp.1,decreasing = FALSE)) 168 | i = 1 169 | for (i in 1:nrow(dat)) { 170 | dat[i,3] <- tmp.2$new[match(dat[i,3],tmp.2$ori)] 171 | } 172 | dat$mean = NULL 173 | dat = dat[match(dat$group,aa$group),][,c(2,1)] %>% as.data.frame() 174 | row.names(dat) = dat$group 175 | return(list(dat,wilcox = krusk,kruskal = sumkrusk)) 176 | } 177 | 178 | 179 | #' Perform ANOVA and run multiple comparisons for more sets of data and order in order to mean value of treatment 180 | #' 181 | #' @param data a data.frame contain the input data 182 | #' @param num index col which to test normality and homogeneity 183 | #' @param method_Mc which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe". 184 | #' @examples 185 | #' # data(data_wt) 186 | #' result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 187 | #' # utput result for multiple comparison results 188 | #' result 189 | #' @return data frame 190 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{2018203048@@njau.edu.cn} 191 | #' @references 192 | #' 193 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 194 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 195 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 196 | #' @export 197 | 198 | MuiaovMcomper2 = function(data = data_wt,num = c(4:6),method_Mc = "Tukey"){ 199 | data$group = as.factor(data$group) 200 | N = num[1] 201 | result = aovMcomper2 (data = data, i= N,method_Mc = method_Mc) 202 | aa = result[[1]] 203 | name = colnames(data[N]) 204 | colnames(aa)[1] = name 205 | aa$group = NULL 206 | A = aa 207 | 208 | for (N in num[-1]) { 209 | result = aovMcomper2 (data = data, i= N,method_Mc = method_Mc) 210 | aa = result[[1]] 211 | name = colnames(data[N]) 212 | 213 | colnames(aa)[1] = name 214 | aa <- aa[match(row.names(A),row.names(aa)),] 215 | aa$group = NULL 216 | A <- merge(A,aa,by = "row.names",all = T) 217 | row.names(A) = A$Row.names 218 | A$Row.names = NULL 219 | } 220 | 221 | return(A) 222 | } 223 | 224 | 225 | #' Multi-group data for non-parametric test 226 | #' 227 | #' @param data a data.frame contain the input data and order in order to mean value of treatment 228 | #' @param num index col which need plot 229 | #' @examples 230 | #' # data(data_wt) 231 | #' result = MuiKwWlx(data = data_wt,num = c(4:6)) 232 | #' result 233 | #' @return data frame 234 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} 235 | #' @references 236 | #' 237 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 238 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 239 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 240 | #' @export 241 | 242 | MuiKwWlx2 = function(data = data_wt,num = c(4:6)){ 243 | N = num[1] 244 | 245 | data_wt = data 246 | result = KwWlx2(data = data_wt, i= N) 247 | aa = result[[1]] 248 | name = colnames(data_wt[N]) 249 | 250 | colnames(aa)[1] = name 251 | aa$group = NULL 252 | A = aa 253 | 254 | for (N in num[-1]) { 255 | result = KwWlx2(data = data_wt, i= N) 256 | aa = result[[1]] 257 | name = colnames(data_wt[N]) 258 | 259 | colnames(aa)[1] = name 260 | aa$group = NULL 261 | 262 | A <- merge(A,aa,by = "row.names",all = T) 263 | row.names(A) = A$Row.names 264 | A$Row.names = NULL 265 | 266 | 267 | 268 | } 269 | 270 | return(A) 271 | 272 | } 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | -------------------------------------------------------------------------------- /R/value_stackBar.R: -------------------------------------------------------------------------------- 1 | #' Stacked histograms add error bars, marked by significance 2 | #' 3 | #' @param data a data.frame contain the input data 4 | #' @param i col index wtich need to test 5 | #' @param errbar add a distinctive label, TRUE or FEASE could be selected 6 | #' @param result output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame) 7 | #' @param add_abc add sig abc T or F 8 | #' @examples 9 | #' # data(data_wt) 10 | #'result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 11 | #'res <- value_stackBar(data = data_wt,i = c(4,9,8) ,result = result, 12 | #' add_abc = TRUE) 13 | #'res[[1]] 14 | #' @return list 15 | #' @author Contact: Tao Wen \email{2018203048@@njau.edu.cn} Jun Yuan \email{junyuan@@njau.edu.cn} PengHao Xie \email{2019103106@@njau.edu.cn} 16 | #' @references 17 | #' 18 | #' Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 19 | #' Root exudates drive the soil-borne legacy of aboveground pathogen infection 20 | #' Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 21 | #' @export 22 | 23 | 24 | 25 | value_stackBar = function( 26 | data = data, 27 | i, 28 | result = result, 29 | add_abc = TRUE 30 | ){ 31 | i = c(1,2,i) 32 | data <- data[i] 33 | tem = data[,c(-1)] 34 | colnames(tem)[1] = "id" 35 | 36 | 37 | result$group = row.names(result) 38 | abc <- reshape2::melt(result, id="group", 39 | variable.name="variable", value.name = "abc") 40 | colnames(abc)[1] = "id" 41 | head(tem) 42 | 43 | mean = function(x) { 44 | base::mean(x,na.rm = TRUE) 45 | } 46 | tem.2 = tem %>% dplyr::group_by(id) %>% 47 | dplyr::summarise_if(is.numeric, mean) %>% 48 | as.data.frame() 49 | count = tem.2[,c(-1)] 50 | tem.2[,c(-1)] = t(t(count)/colSums(count)) 51 | 52 | pcm = reshape2::melt(tem.2, id = c("id")) 53 | 54 | dat = pcm %>% dplyr::left_join(abc) 55 | if (add_abc == FALSE) { 56 | p1 = ggplot(dat, aes(x = value, y = variable,group = id,fill = id)) + 57 | geom_bar(stat="identity",color="black", width=.6) + 58 | theme( 59 | panel.background=element_blank(), 60 | panel.grid=element_blank(), 61 | axis.text.x = element_text(colour = "black",angle = 90) 62 | ) 63 | tem.6 = dat 64 | } 65 | 66 | if (add_abc == TRUE) { 67 | ## Data statistics mean, standard deviation, standard error 68 | labfun = function(x) { 69 | cumsum(x) - 0.5*x 70 | } 71 | tem.3 <- stats::aggregate(pcm$value, by=list(pcm$variable), 72 | FUN= labfun) 73 | 74 | tem.3 = data.frame(group = tem.3$Group.1,tem.3$x) 75 | tem.id = pcm$id %>% unique() %>% as.character() 76 | colnames(tem.3) = c("variable",tem.id) 77 | head(tem.3) 78 | tem.4 = reshape2::melt(tem.3, id = c("variable")) 79 | colnames(tem.4) = c("variable","id","label_x") 80 | 81 | tem.5 = pcm %>% 82 | dplyr::left_join(abc) 83 | 84 | tem.6 = tem.5 %>% 85 | dplyr::left_join(tem.4) 86 | 87 | head(tem.6) 88 | tem.6$id = factor(tem.6$id,levels = tem.id[length(tem.id):1] ) 89 | 90 | 91 | p1 = ggplot(tem.6, aes(x = value, y = variable,group = id,fill = id)) + 92 | geom_bar(stat="identity",color="black", width=.6) + 93 | geom_text(aes(x = label_x, label = abc),size = 2) + 94 | theme( 95 | panel.background=element_blank(), 96 | panel.grid=element_blank(), 97 | axis.text.x = element_text(colour = "black",angle = 90) 98 | ) 99 | } 100 | 101 | return(list(p1,tem.6)) 102 | } 103 | 104 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "EasyStat_help" 3 | author: "wentao" 4 | date: "2020/1/11" 5 | output: html_document 6 | --- 7 | ```{css include=FALSE} 8 | pre code,pre,code { 9 | white-space:pre!important; 10 | overflow-x: scroll!important; 11 | } 12 | ``` 13 | 14 | ```{r setup, include=FALSE} 15 | knitr::opts_chunk$set(echo = TRUE, 16 | fig.width = 7, 17 | fig.height = 5, 18 | fig.align = "center", 19 | warning = FALSE, 20 | message = FALSE 21 | 22 | ) 23 | ``` 24 | 25 | # 差异分析完整解决方案 26 | 27 | 前一段时间推出了包存在一些细节问题:譬如: 28 | - 非参数检验无字母标注混乱。 29 | - 其次,由于我在做差异检测和出图的时候需要制定同样的数据,所以i设置要相同,之前我没有设置相同,所有将其他列的差异检测结果映射到了别的数据,导致上一篇推送字母标注问题。 30 | 31 | 目前本包函数其他函数有些小问题,我已经修正,所以大家使用起来应该放心,我修改了示例数据,增加到每个处理6个重复,所以可以更好的作为示例数据再次为大家演示一遍。 32 | 33 | > 感谢大家的关注,也会让这个包更加好用,本次处理修正一些错误之外,我还添加的新的出图样式。来源于2020年2月刚刚online的NBT文章。大家继续往后看吧。 34 | 35 | ## EasyStat 使用指南 36 | 37 | 安装EasyStat包 38 | 39 | ```{R eval=FALSE, include=FALSE} 40 | library(devtools) 41 | install_github("taowenmicro/EasyStat") 42 | 43 | # 如果国外不可用,则使用国内备份安装 44 | remotes::install_git('https://gitee.com/wentaomicro/EasyStat') 45 | 46 | ``` 47 | 48 | 导入包和数据,数据均来自真实试验和文公开文献下载,通过调整分组加入。 49 | 50 | ```{R} 51 | # 导入差异分析包 52 | library(EasyStat) 53 | # 导入作图所需要的ggplot包 54 | library(ggplot2) 55 | 56 | #使用内置数据1 57 | data(data_wt) 58 | 59 | #内置数据2 60 | data(env) 61 | 62 | 63 | ``` 64 | 65 | ![image](./0.png) 66 | 67 | ### 基于单个指标的统计分析 68 | 69 | 正态检验和方差齐性分析,使用?NorNorCVTest查看帮助信息,你会发现目前帮助信息都是使用中文写的,不过随着包的逐渐成熟,和功能的不断完善,将逐渐使用英文编写帮助文档。 70 | 71 | 72 | ```{R} 73 | # 使用?NorNorCVTest查看帮助信息 74 | ##使用案例 75 | NorCV = NorNorCVTest(data = data_wt, i= 4,method_cv = "leveneTest") 76 | #提取正态检验结果 77 | NorCV[[1]] 78 | #提取方差齐性检验结果 79 | NorCV[[2]] 80 | 81 | ``` 82 | norm.test会按照分组告诉大家是否符合正态分布。 83 | 84 | ### 方差分析(aovMcomper) 85 | 86 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 87 | 88 | - i:代表您想要进行统计的列,比如:第三列:i = 3 89 | 90 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 91 | ```{R} 92 | # ?aovMcomper 93 | result= aovMcomper (data = data_wt, i= 5,method_Mc = "Tukey") 94 | # 提取多重比较结果 95 | result[[1]] 96 | #提取方差检验结果 97 | result[[2]] 98 | ``` 99 | 结果中多重比较的展示全部使用字母表示了,虽然许多多种比较方法默认展示方式不同,但是我已经在包中将这些展示方式调整一致为字母。 100 | 101 | 102 | ### 非参数检验 103 | 两个参数代表的意义与方差分析的两个相同; 104 | 105 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 106 | 107 | - i:代表您想要进行统计的列,比如:第三列:i = 3 108 | 109 | 110 | ```{R} 111 | # ?KwWlx 112 | res = KwWlx(data = data_wt, i= 5) 113 | # 调用非参数两两比较结果:字母标记展示 114 | res[[1]] 115 | #表格展示两两之间差异结果 116 | res[[2]] 117 | 118 | 119 | ``` 120 | 121 | ## 差异可视化方案(两种差异表示,三种图形展示) 122 | 123 | 124 | ### 柱状图展示方差分析或非参数检验结果(aovMuiBarPlot) 125 | 在这个包中将差异检测和出图部分分离,方便选择合适的图表和差异可视化的策略。最终要的参数是result :为前面差异分析结果中的第一个表单,格式为第一列差异显著字母,第二列分组标签,列名,分组标签。如果只是用可视化的函数,直接从外面导入类似数据即可。 126 | 127 | ```{R} 128 | # ?aovMuiBarPlot 129 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 130 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 5,sig_show ="abc",result = result[[1]]) 131 | #提取结果 132 | PlotresultBar[[1]] 133 | #提取方差分析或非参数检验结果 134 | PlotresultBar[[2]] 135 | ``` 136 | 137 | ```{R} 138 | # ?aovMuiBarPlot 139 | ###----使用方差检验结果和多重比较结果做展示: 柱状图展示 140 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 5,sig_show ="line",result = result[[1]]) 141 | #提取结果 142 | PlotresultBar[[1]] 143 | #提取方差分析或非参数检验结果 144 | PlotresultBar[[2]] 145 | ``` 146 | 147 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 148 | 149 | - i:代表您想要进行统计的列,比如:第三列:i = 3 150 | 151 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 152 | 153 | - result:代表显著性差异分析结果,是一个数据框,第一列是显著性差异字母,第二列是分组group 154 | 155 | #### 箱线图展示方差分析或非参数检验结果(aovMuiBoxP) 156 | 157 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 158 | 159 | - i:代表您想要进行统计的列,比如:第三列:i = 3 160 | 161 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 162 | 163 | - result:代表显著性差异分析结果,是一个数据框,第一列是显著性差异字母,第二列是分组group 164 | 165 | ```{R} 166 | # ?aovMuiBoxP 167 | # #使用案例 168 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 5,sig_show ="abc",result = result[[1]]) 169 | # 提取检验结果 170 | PlotresultBox[[2]] 171 | #提取图片 172 | p = PlotresultBox[[1]] 173 | p 174 | 175 | ``` 176 | 177 | 178 | ```{R} 179 | # ?aovMuiBoxP 180 | # #使用案例 181 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 5,sig_show ="line",result = result[[1]]) 182 | # 提取检验结果 183 | PlotresultBox[[2]] 184 | #提取图片 185 | p = PlotresultBox[[1]] 186 | p 187 | 188 | ``` 189 | ### 点柱图-完美解决柱状图无法展示样本信息的缺陷 190 | 191 | ```{R} 192 | # result= aovMcomper (data = data_wt, i= 5,method_Mc = "Tukey") 193 | # # 提取多重比较结果 194 | # result[[1]] 195 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 5,sig_show ="abc",result = result[[1]]) 196 | #提取图片 197 | p = PlotresultBox[[1]] 198 | p 199 | ``` 200 | 201 | EasyStat包为什么能完美解决差异分析呢.因为他比你想象的要强大。下面使用连线形式展示差异,显著的差异按照标注星号,不显著的标注ns。 202 | 203 | ```{R} 204 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 5,sig_show ="line",result = result[[1]]) 205 | #提取图片 206 | p = PlotresultBox[[1]] 207 | p 208 | ``` 209 | 210 | ## 多指标模式 211 | 212 | ### 多个指标同时做正态检验和方差齐性分析(MuiNorCV) 213 | 214 | 这里对多组数据进行分析,结果我是用T或F代表,方便阅读。 215 | 216 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 217 | 218 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 219 | 220 | - method_cv:代表选择方差齐性的方法,有两种可供选择:method_cv == "bartlett.test" ;method_cv == "leveneTest" 221 | ```{R} 222 | dim(data_wt) 223 | # ?MuiNorCV 224 | # 使用案例 225 | norCv = MuiNorCV(data = data_wt,num = c(4:10),method_cv = "leveneTest") 226 | #展示正态检验和方差齐性结果 227 | norCv 228 | 229 | ``` 230 | 这里由于指标比较多,所以我将结果进行简化,直接使用ture和false来提示大家,cor是正态性检测组,cv是方差齐性检测。 231 | 232 | #### 多个指标方差检验(MuiaovMcomper) 233 | 234 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 235 | 236 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 237 | 238 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc = "LSD";method_Mc = "SNK";method_Mc = "Duncan";method_Mc ="scheffe" 239 | 240 | 241 | ```{R} 242 | # ? MuiaovMcomper 243 | # #使用案例 244 | result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 245 | #提取每个指标方差检验多重比较结果 246 | result 247 | 248 | ``` 249 | 同样,多个指标展示按照指标每列为一组检测结果。 250 | 251 | ### 多个指标非参数检验(MuiKwWlx) 252 | 253 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是测定或者收集的指标了 254 | 255 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 256 | 257 | ```{R} 258 | # ? MuiKwWlx 259 | # #使用案例 260 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 261 | #提取每个指标非参数检验多重比较结果 262 | result 263 | 264 | ``` 265 | 266 | 结果和多组方差分析结果一样。很好用于后面的出图,同样也适合自己导入数据,使用出图 267 | 268 | 269 | ### 多组数据可视化差异分析结果: 柱状图(MuiPlotresultBar) 270 | 271 | 多组指标分开出图,比较麻烦的是图形的保存,如果还需要让你一个一个保存图片,那也是相当繁琐的,所以这里我设置了自动保存,也只有这种方式是自动保存,其他单个,多组分面图形较少,所以就可以自己保存。 272 | 273 | 我让该函数自动保存每个指标的出图文件到当前文件夹中。这些文件以该指标名称命名; 274 | 275 | 276 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 277 | 278 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 279 | 280 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 281 | 282 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 283 | 284 | ```{R} 285 | # ?MuiPlotresultBar 286 | # # #使用案例 287 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 288 | result 289 | # #结果直接输出到文件夹中 290 | MuiPlotresultBar(data = data_wt,num = c(4:6),result = result ,sig_show ="line") 291 | 292 | 293 | ``` 294 | 295 | ### 多组数据可视化差异分析结果:箱线图(MuiPlotresultBox) 296 | 297 | 我让该函数自动保存每个指标的出图文件到当前文件夹中。这些文件以该指标名称命名; 298 | 299 | 300 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 301 | 302 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 303 | 304 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 305 | 306 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 307 | ```{R} 308 | # ?MuiPlotresultBox 309 | #使用案例 310 | result = MuiKwWlx(data = data_wt,num = c(4:8)) 311 | result 312 | # #直接出图到文件夹中 313 | MuiPlotresultBox(data = data_wt,num = c(4:8),result = result,sig_show ="abc") 314 | 315 | ``` 316 | ### 线柱图 317 | 输入和箱线图一致 318 | ```{R} 319 | # ?MuiPlotresultBox 320 | #使用案例 321 | result = MuiKwWlx(data = data_wt,num = c(4:8)) 322 | result 323 | # #直接出图到文件夹中 324 | MuiPlotReBoxBar(data = data_wt,num = c(4:8),result = result,sig_show ="line") 325 | 326 | ``` 327 | 328 | #### 差异结果展示:分面展示柱状图:(FacetMuiPlotresultBar) 329 | 330 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 331 | 332 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 333 | 334 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 335 | 336 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 337 | - ncol:代表分面展示每一行放几张图 338 | ```{R} 339 | # ?FacetMuiPlotresultBar 340 | # # #使用案例 341 | result = MuiaovMcomper(data = data_wt,num = c(4:11),method_Mc = "Tukey") 342 | result 343 | result1 = FacetMuiPlotresultBar(data = data_wt,num = c(4:11),result = result,sig_show ="abc",ncol = 4 ) 344 | result1[[1]] 345 | 346 | ``` 347 | 348 | ### 差异结果展示:分面展示柱状图:(FacetMuiPlotresultBox) 349 | 350 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 351 | 352 | - num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 353 | 354 | - sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 355 | 356 | - result:代表显著性差异分析结果,是一个数据框,每一列是显著性标记字母,MuiKwWlx 357 | - ncol:代表分面展示每一行放几张图 358 | ```{R} 359 | # ?FacetMuiPlotresultBox 360 | # #使用案例 361 | result = MuiKwWlx(data = data_wt,num = c(4:11)) 362 | result 363 | # 364 | result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:11),result = result,sig_show ="abc",ncol = 4 ) 365 | result1[[1]] 366 | 367 | ``` 368 | 369 | 370 | 371 | 372 | 使用两种方法,我们可以对比非参数检验和方差检验结果是否一致 373 | 374 | ### 下面使用线柱图展示 375 | ```{R} 376 | library(ggplot2) 377 | # ?FacetMuiPlotresultBox 378 | # #使用案例 379 | result = MuiKwWlx(data = data_wt,num = c(4:11)) 380 | result 381 | # 382 | result1 = FacetMuiPlotReBoxBar(data = data_wt,num = c(4:11),result = result,sig_show ="abc",ncol = 4 ) 383 | result1[[1]] + theme_bw() 384 | 385 | ``` 386 | 387 | 388 | 注意以上三种分面展示的目前仅支持字母标注显著性,连线形式的尚未添加。 389 | 390 | ### 单个指标一体化分析(SingleStat) 391 | 392 | 这个函数可以将我们的目标列做正态检验和方差齐性,然后根据结果选择方差检验或者多重比较方法,最后选择自己需要的出图方式和显著性标记方式展示。 393 | 394 | - data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 395 | 396 | - i:代表您想要进行统计的列,比如:第三列:i = 3 397 | 398 | - method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 399 | 400 | - plot:可以选择需要的出图类型,柱状图和箱线图 401 | 402 | 403 | ```{R} 404 | # ?SingleStat 405 | # # #使用案例 406 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 407 | result = SingleStat(data = data_wt,plot = "bar",method_Mc = "Tukey",i= 4,sig_show ="abc") 408 | # #导出图片 409 | p = result[[1]] 410 | p 411 | 412 | ``` 413 | 414 | 可以更换出图方式,当然这里会自动判断使用方差分析,还是非参数检验。选择结果会展示在结果的第三个列表中,可自行查看。 415 | ```{R} 416 | # ?SingleStat 417 | # # #使用案例 418 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 419 | result = SingleStat(data = data_wt,plot = "box",method_Mc = "Tukey",i= 4,sig_show ="abc") 420 | # 提取差异检测结果 421 | result[[2]] 422 | # 提取差异检测放啊 423 | result[[3]] 424 | 425 | # #导出图片 426 | p = result[[1]] 427 | p 428 | 429 | 430 | ``` 431 | 432 | ```{R} 433 | # ?SingleStat 434 | # # #使用案例 435 | # #输出结果第一个为图片,第二个是统计结果,第三个是统计方法 436 | result = SingleStat(data = data_wt,plot = "boxbar",method_Mc = "Tukey",i= 4,sig_show ="abc") 437 | # 提取差异检测结果 438 | result[[2]] 439 | # 提取差异检测放啊 440 | result[[3]] 441 | 442 | # #导出图片 443 | p = result[[1]] 444 | p 445 | 446 | 447 | ``` 448 | 449 | 450 | 451 | 452 | ### 多个指标一体化分析(MuiStat) 453 | 454 | 实现了多个指标批量整体运行;这个函数可以将我们的目标列做正态检验和方差齐性,然后根据结果选择方差检验或者多重比较方法,最后选择自己需要的出图方式和显著性标记方式展示。 455 | 456 | ```{R} 457 | # ?MuiStat 458 | #使用案例 459 | result = MuiStat(data = data_wt,num = c(4:11),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "box",plottype = "mui") 460 | result[[1]] 461 | 462 | # 提取方差检测的列 463 | result$aov 464 | # 提取f非参数检测的列 465 | result$wlx 466 | # 提取差异检测结果 467 | result$table 468 | ``` 469 | 470 | 柱状图 471 | 472 | ```{R} 473 | 474 | result = MuiStat(data = data_wt,num = c(4:11),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "bar",plottype = "mui") 475 | result[[1]] 476 | 477 | ``` 478 | 479 | ```{R} 480 | 481 | result = MuiStat(data = data_wt,num = c(4:11),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 4,plot = "boxbar",plottype = "mui") 482 | result[[1]] 483 | 484 | ``` 485 | 486 | data:输入数据框,第一列为样本编号,第二列为分组,注意分组标签必须设定为group,第三列以后就是妮妮测定或者收集的指标了 487 | 488 | num:代表您想要进行统计的列,这里可以输入多个列,只需要指定列号即可:例如:num = c(4:6) 489 | 490 | method_cv:代表选择方差齐性的方法,有两种可供选择:method_cv == "bartlett.test" ;method_cv == "leveneTest" 491 | 492 | method_Mc:选择需要使用的多重比较方法,这里又多种方法可供选择:method_Mc == "LSD";method_Mc == "SNK";method_Mc == "Duncan";method_Mc == "scheffe" 493 | 494 | plot:可以选择需要的出图类型,柱状图和箱线图 495 | 496 | sig_show:代表差异展示方式;sig_show ="abc"是使用字母表示;sig_show ="line"是使用连线和星号表示;如果是NA,那么就不显示显著性结果 497 | 498 | ncol:代表分面展示每一行放几张图 499 | 500 | plottype:输出图形是分面展示plottype =mui,还是单张展示:plottype == "single" 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | # EasyStat 514 | # EasyStat 515 | -------------------------------------------------------------------------------- /data/data_wt.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taowenmicro/EasyStat/e2572ef73247acf590735adc0bde9961e2d64043/data/data_wt.rda -------------------------------------------------------------------------------- /data/env.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taowenmicro/EasyStat/e2572ef73247acf590735adc0bde9961e2d64043/data/env.rda -------------------------------------------------------------------------------- /data/ps1.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taowenmicro/EasyStat/e2572ef73247acf590735adc0bde9961e2d64043/data/ps1.rda -------------------------------------------------------------------------------- /data/ps2.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/taowenmicro/EasyStat/e2572ef73247acf590735adc0bde9961e2d64043/data/ps2.rda -------------------------------------------------------------------------------- /man/FacetMuiPlotReBoxBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FacetMuiPlotReBoxBar.R 3 | \name{FacetMuiPlotReBoxBar} 4 | \alias{FacetMuiPlotReBoxBar} 5 | \title{Use facets to show the results of variance analysis, box+bar plot selected} 6 | \usage{ 7 | FacetMuiPlotReBoxBar( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | ncol = 3, 13 | fac.level = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection.} 18 | 19 | \item{num}{col index wtich need to test} 20 | 21 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 22 | 23 | \item{sig_show}{Distinctive display, "abc" or "line"} 24 | 25 | \item{ncol}{If you choose faceted display, choose to place several graphics per line} 26 | } 27 | \value{ 28 | list 29 | } 30 | \description{ 31 | Use facets to show the results of variance analysis, box+bar plot selected 32 | } 33 | \examples{ 34 | # data(data_wt) 35 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 36 | result1 = FacetMuiPlotReBoxBar (data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 37 | result1[[1]] 38 | } 39 | \references{ 40 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 41 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 42 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 43 | } 44 | \author{ 45 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 46 | } 47 | -------------------------------------------------------------------------------- /man/FacetMuiPlotresultBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FacetMuiPlotresultBar.R 3 | \name{FacetMuiPlotresultBar} 4 | \alias{FacetMuiPlotresultBar} 5 | \title{Use facets to show the results of variance analysis, bar plot selected} 6 | \usage{ 7 | FacetMuiPlotresultBar( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | ncol = 3, 13 | fac.level = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection.} 18 | 19 | \item{num}{col index wtich need to test} 20 | 21 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 22 | 23 | \item{sig_show}{Distinctive display, "abc" or "line"} 24 | 25 | \item{ncol}{If you choose faceted display, choose to place several graphics per line} 26 | } 27 | \value{ 28 | list 29 | } 30 | \description{ 31 | Use facets to show the results of variance analysis, bar plot selected 32 | } 33 | \examples{ 34 | # data(data_wt) 35 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 36 | result1 = FacetMuiPlotresultBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 37 | result1[[1]] 38 | } 39 | \references{ 40 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 41 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 42 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 43 | } 44 | \author{ 45 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 46 | } 47 | -------------------------------------------------------------------------------- /man/FacetMuiPlotresultBox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FacetMuiPlotresultBox.R 3 | \name{FacetMuiPlotresultBox} 4 | \alias{FacetMuiPlotresultBox} 5 | \title{Use facets to show the results of variance analysis, box plot selected} 6 | \usage{ 7 | FacetMuiPlotresultBox( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | ncol = 3, 13 | fac.level = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection.} 18 | 19 | \item{num}{col index wtich need to test} 20 | 21 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 22 | 23 | \item{sig_show}{Distinctive display, "abc" or "line"} 24 | 25 | \item{ncol}{If you choose faceted display, choose to place several graphics per line} 26 | 27 | \item{loc}{cahnge the label of "abc" to Suitable location} 28 | } 29 | \value{ 30 | list 31 | } 32 | \description{ 33 | Use facets to show the results of variance analysis, box plot selected 34 | } 35 | \examples{ 36 | # data(data_wt) 37 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 38 | result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 39 | result1[[1]] 40 | } 41 | \references{ 42 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 43 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 44 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 45 | } 46 | \author{ 47 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 48 | } 49 | -------------------------------------------------------------------------------- /man/FacetMuiPlotresultBox2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FacetMuiPlotresultBox2.R 3 | \name{FacetMuiPlotresultBox2} 4 | \alias{FacetMuiPlotresultBox2} 5 | \title{Use facets to show the results of variance analysis, box plot selected} 6 | \usage{ 7 | FacetMuiPlotresultBox2( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | ncol = 3, 13 | fac.level = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{data}{a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection.} 18 | 19 | \item{num}{col index wtich need to test} 20 | 21 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 22 | 23 | \item{sig_show}{Distinctive display, "abc" or "line"} 24 | 25 | \item{ncol}{If you choose faceted display, choose to place several graphics per line} 26 | 27 | \item{loc}{cahnge the label of "abc" to Suitable location} 28 | } 29 | \value{ 30 | list 31 | } 32 | \description{ 33 | Use facets to show the results of variance analysis, box plot selected 34 | } 35 | \examples{ 36 | # data(data_wt) 37 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 38 | result1 = FacetMuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc",ncol = 2 ) 39 | result1[[1]] 40 | } 41 | \references{ 42 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 43 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 44 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 45 | } 46 | \author{ 47 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 48 | } 49 | -------------------------------------------------------------------------------- /man/GroupBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GroupBar.R 3 | \name{GroupBar} 4 | \alias{GroupBar} 5 | \title{Variance test or non-parametric test results visualization, using boxbar} 6 | \usage{ 7 | GroupBar( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | ylimit = 1.2 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{num}{index col which need plot} 19 | 20 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 21 | 22 | \item{sig_show}{Distinctive display, "abc" or we could find in the future} 23 | 24 | \item{ylimit}{Adjust the y-axis coordinate range} 25 | } 26 | \value{ 27 | list 28 | } 29 | \description{ 30 | Variance test or non-parametric test results visualization, using boxbar 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 35 | result = GroupBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 36 | # output result 37 | result[[1]] 38 | 39 | } 40 | \references{ 41 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 42 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 43 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 44 | } 45 | \author{ 46 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 47 | } 48 | -------------------------------------------------------------------------------- /man/KwWlx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/KwWlx.R 3 | \name{KwWlx} 4 | \alias{KwWlx} 5 | \title{Easy for Non-parametric test} 6 | \usage{ 7 | KwWlx(data = data_wt, i = 3, method = "wilcox.test") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method}{wilcox.test or t.test could be seleced.} 15 | } 16 | \value{ 17 | list with two data frame 18 | } 19 | \description{ 20 | Easy for Non-parametric test 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result = KwWlx(data = data_wt, i= 4) 25 | result[[1]] 26 | } 27 | \references{ 28 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 29 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 30 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 31 | } 32 | \author{ 33 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 34 | } 35 | -------------------------------------------------------------------------------- /man/KwWlx2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/util.R 3 | \name{KwWlx2} 4 | \alias{KwWlx2} 5 | \title{Easy for Non-parametric test and order in order to mean value of treatment} 6 | \usage{ 7 | KwWlx2(data = data_wt, i = 3, method = "wilcox.test") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method}{wilcox.test or t.test could be seleced.} 15 | } 16 | \value{ 17 | list with two data frame 18 | } 19 | \description{ 20 | Easy for Non-parametric test and order in order to mean value of treatment 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result = KwWlx2(data = data_wt, i= 4) 25 | result[[1]] 26 | } 27 | \references{ 28 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 29 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 30 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 31 | } 32 | \author{ 33 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 34 | } 35 | -------------------------------------------------------------------------------- /man/KwWlxPair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/KwWlxPair.R 3 | \name{KwWlxPair} 4 | \alias{KwWlxPair} 5 | \title{Easy for Non-parametric test} 6 | \usage{ 7 | KwWlxPair(data = data_wt, i = 3, method = "wilcox.test", paired = FALSE) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method}{"t.test" or "wilcox.test" could be selected by method} 15 | 16 | \item{paired}{a logical indicating whether you want a paired test. Used in t.test and in wilcox.test.} 17 | } 18 | \value{ 19 | data frame 20 | } 21 | \description{ 22 | Easy for Non-parametric test 23 | } 24 | \examples{ 25 | # data(data_wt) 26 | result = KwWlx2(data = data_wt, i= 4,method = "t.test",paired = FALSE) 27 | result[[1]] 28 | } 29 | \references{ 30 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 31 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 32 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 33 | } 34 | \author{ 35 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 36 | } 37 | -------------------------------------------------------------------------------- /man/MuiHeatmapBubplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiHeatmapBubplot.R 3 | \name{MuiHeatmapBubplot} 4 | \alias{MuiHeatmapBubplot} 5 | \title{MuiHeatmapBubplot} 6 | \usage{ 7 | MuiHeatmapBubplot( 8 | data = data, 9 | i, 10 | result = result, 11 | sample = FALSE, 12 | scale = TRUE, 13 | col_cluster = TRUE, 14 | row_cluster = TRUE, 15 | label = TRUE 16 | ) 17 | } 18 | \arguments{ 19 | \item{data}{a data.frame contain the input data} 20 | 21 | \item{i}{col index wtich need to test} 22 | 23 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 24 | 25 | \item{sample}{sample or group} 26 | 27 | \item{col_cluster}{only used for sample = TRUE} 28 | 29 | \item{row_cluster}{only used for sample = TRUE} 30 | 31 | \item{label}{only used for sample = TRUE} 32 | 33 | \item{errbar}{add a distinctive label, TRUE or FEASE could be selected} 34 | } 35 | \value{ 36 | list 37 | } 38 | \description{ 39 | MuiHeatmapBubplot 40 | } 41 | \examples{ 42 | # data(data_wt) 43 | result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 44 | res <- MuiHeatmapBubplot(data = data_wt,i = c(4,9,8) ,result = result, 45 | sample = TRUE) 46 | res[[1]] 47 | } 48 | \references{ 49 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 50 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 51 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 52 | } 53 | \author{ 54 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} PengHao Xie \email{2019103106@njau.edu.cn} 55 | } 56 | -------------------------------------------------------------------------------- /man/MuiKwWlx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiKwWlx.R 3 | \name{MuiKwWlx} 4 | \alias{MuiKwWlx} 5 | \title{Multi-group data for non-parametric test} 6 | \usage{ 7 | MuiKwWlx(data = data_wt, num = c(4:6)) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{num}{index col which need plot} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Multi-group data for non-parametric test 19 | } 20 | \examples{ 21 | # data(data_wt) 22 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 23 | result 24 | } 25 | \references{ 26 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 27 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 28 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 29 | } 30 | \author{ 31 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 32 | } 33 | -------------------------------------------------------------------------------- /man/MuiKwWlx2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/util.R 3 | \name{MuiKwWlx2} 4 | \alias{MuiKwWlx2} 5 | \title{Multi-group data for non-parametric test} 6 | \usage{ 7 | MuiKwWlx2(data = data_wt, num = c(4:6)) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data and order in order to mean value of treatment} 11 | 12 | \item{num}{index col which need plot} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Multi-group data for non-parametric test 19 | } 20 | \examples{ 21 | # data(data_wt) 22 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 23 | result 24 | } 25 | \references{ 26 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 27 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 28 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 29 | } 30 | \author{ 31 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 32 | } 33 | -------------------------------------------------------------------------------- /man/MuiKwWlxPair.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiKwWlxPair.R 3 | \name{MuiKwWlxPair} 4 | \alias{MuiKwWlxPair} 5 | \title{Multi-group data for non-parametric test paired show...} 6 | \usage{ 7 | MuiKwWlxPair(data = data_wt, num = c(4:6)) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{num}{index col which need plot} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Multi-group data for non-parametric test paired show... 19 | } 20 | \examples{ 21 | # data(data_wt) 22 | result = MuiKwWlxPair(data = data_wt,num = c(4:6)) 23 | result 24 | } 25 | \references{ 26 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 27 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 28 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 29 | } 30 | \author{ 31 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 32 | } 33 | -------------------------------------------------------------------------------- /man/MuiNorCV.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiNorCV.R 3 | \name{MuiNorCV} 4 | \alias{MuiNorCV} 5 | \title{Test normality and homogeneity of variance of inputmore sets of data} 6 | \usage{ 7 | MuiNorCV(data = data_wt, num = c(4:6), method_cv = "leveneTest") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{num}{index col which to test normality and homogeneity} 13 | 14 | \item{method_cv}{which method to test variance, included "leveneTest","bartlett.test".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Test normality and homogeneity of variance of inputmore sets of data 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | norCv = MuiNorCV(data = data_wt,num = c(4,5,6),method_cv = "leveneTest") 25 | norCv 26 | } 27 | \references{ 28 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 29 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 30 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 31 | } 32 | \author{ 33 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 34 | } 35 | -------------------------------------------------------------------------------- /man/MuiPlotReBoxBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiPlotReBoxBar.R 3 | \name{MuiPlotReBoxBar} 4 | \alias{MuiPlotReBoxBar} 5 | \title{Visualize multiple sets of data Scatter plot + barplot} 6 | \usage{ 7 | MuiPlotReBoxBar( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | path = "./MuiboxBar/" 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{num}{col index wtich need to test} 19 | 20 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 21 | 22 | \item{sig_show}{Distinctive display, "abc" or "line"} 23 | 24 | \item{path}{creat a folder to save the single plot.} 25 | } 26 | \value{ 27 | list 28 | } 29 | \description{ 30 | Visualize multiple sets of data Scatter plot + barplot 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = KwWlx(data = data_wt, i= 4) 35 | MuiPlotReBoxBar(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 36 | 37 | } 38 | \references{ 39 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 40 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 41 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 42 | } 43 | \author{ 44 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 45 | } 46 | -------------------------------------------------------------------------------- /man/MuiPlotStackBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiPlotStackBar.R 3 | \name{MuiPlotStackBar} 4 | \alias{MuiPlotStackBar} 5 | \title{Stacked histograms add error bars, marked by significance} 6 | \usage{ 7 | MuiPlotStackBar( 8 | data = data, 9 | i, 10 | result = result, 11 | errbar = TRUE, 12 | add_abc = TRUE, 13 | order = FALSE, 14 | sample = FALSE, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{data}{a data.frame contain the input data} 20 | 21 | \item{i}{col index wtich need to test} 22 | 23 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 24 | 25 | \item{errbar}{add a distinctive label, TRUE or FEASE could be selected} 26 | 27 | \item{add_abc}{add sig abc T or F} 28 | 29 | \item{order}{order with colnames according to value} 30 | 31 | \item{sample}{T or F show sample data not group data} 32 | } 33 | \value{ 34 | list 35 | } 36 | \description{ 37 | Stacked histograms add error bars, marked by significance 38 | } 39 | \examples{ 40 | # data(data_wt) 41 | result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 42 | res <- MuiPlotStackBar(data = data,i = c(4,9,8) ,result = result) 43 | # utput result 44 | res[[1]] 45 | } 46 | \references{ 47 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 48 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 49 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 50 | } 51 | \author{ 52 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} PengHao Xie \email{2019103106@njau.edu.cn} 53 | } 54 | -------------------------------------------------------------------------------- /man/MuiPlotresultBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiPlotresultBar.R 3 | \name{MuiPlotresultBar} 4 | \alias{MuiPlotresultBar} 5 | \title{Visualize multiple sets of data barplot} 6 | \usage{ 7 | MuiPlotresultBar( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | path = "./Muibar/" 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{num}{col index wtich need to test} 19 | 20 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 21 | 22 | \item{sig_show}{Distinctive display, "abc" or "line"} 23 | 24 | \item{path}{creat a folder to save the single plot.} 25 | } 26 | \value{ 27 | list 28 | } 29 | \description{ 30 | Visualize multiple sets of data barplot 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = MuiKwWlx(data = data_wt,num = c(4:6)) 35 | MuiPlotresultBar(data = data_wt,num = c(4:6),result = result ,sig_show ="line") 36 | 37 | } 38 | \references{ 39 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 40 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 41 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 42 | } 43 | \author{ 44 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 45 | } 46 | -------------------------------------------------------------------------------- /man/MuiPlotresultBox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiPlotresultBox.R, R/MuiPlotresultBox2.R 3 | \name{MuiPlotresultBox} 4 | \alias{MuiPlotresultBox} 5 | \title{Visualize multiple sets of data Scatter plot + boxplot} 6 | \usage{ 7 | MuiPlotresultBox( 8 | data = data_wt, 9 | num = c(4:6), 10 | result = result, 11 | sig_show = "abc", 12 | path = "./Muibox/" 13 | ) 14 | 15 | MuiPlotresultBox( 16 | data = data_wt, 17 | num = c(4:6), 18 | result = result, 19 | sig_show = "abc", 20 | path = "./Muibox/" 21 | ) 22 | } 23 | \arguments{ 24 | \item{data}{a data.frame contain the input data} 25 | 26 | \item{num}{col index wtich need to test} 27 | 28 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 29 | 30 | \item{sig_show}{Distinctive display, "abc" or "line"} 31 | 32 | \item{path}{creat a folder to save the single plot.} 33 | } 34 | \value{ 35 | list 36 | 37 | list 38 | } 39 | \description{ 40 | Visualize multiple sets of data Scatter plot + boxplot 41 | 42 | Visualize multiple sets of data Scatter plot + boxplot 43 | } 44 | \examples{ 45 | # data(data_wt) 46 | result = KwWlx(data = data_wt, i= 4) 47 | MuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 48 | 49 | # data(data_wt) 50 | result = KwWlx(data = data_wt, i= 4) 51 | MuiPlotresultBox(data = data_wt,num = c(4:6),result = result,sig_show ="abc") 52 | 53 | } 54 | \references{ 55 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 56 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 57 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 58 | 59 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 60 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 61 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 62 | } 63 | \author{ 64 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 65 | 66 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 67 | } 68 | -------------------------------------------------------------------------------- /man/MuiStat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiStat.R 3 | \name{MuiStat} 4 | \alias{MuiStat} 5 | \title{A complete single-factor difference analysis process for mui col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method.} 6 | \usage{ 7 | MuiStat( 8 | data = data_wt, 9 | num = c(4, 5, 6), 10 | method_cv = "leveneTest", 11 | method_Mc = "Tukey", 12 | sig_show = "abc", 13 | ncol = 2, 14 | plot = "bar", 15 | plottype = "mui", 16 | path = "./output" 17 | ) 18 | } 19 | \arguments{ 20 | \item{data}{a data.frame contain the input data;Enter the data frame, the first column is the sample number, the second column is the group, note that the group label must be set to group, and the third column and later are the indicators for measurement or collection.} 21 | 22 | \item{num}{col index wtich need to test} 23 | 24 | \item{method_cv}{which method to test variance, included "leveneTest","bartlett.test"} 25 | 26 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 27 | 28 | \item{sig_show}{Distinctive display, "abc" or "line"} 29 | 30 | \item{ncol}{If you choose faceted display, choose to place several graphics per line} 31 | 32 | \item{plot}{chose the plot type shuld be a barplot or boxplot or bar+box plot} 33 | 34 | \item{plottype}{select a plot type, included "single" and "mui"} 35 | 36 | \item{path}{creat a folder to save the single plot, if you seleted the model "single"} 37 | } 38 | \value{ 39 | list 40 | } 41 | \description{ 42 | A complete single-factor difference analysis process for mui col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method. 43 | } 44 | \examples{ 45 | # data(data_wt) 46 | result = MuiStat(data = data_wt,num = c(4,5,6),method_cv = "leveneTest",method_Mc = "Tukey",sig_show = "abc",ncol = 2,plot = "boxbar",plottype = "mui") 47 | result[[1]] 48 | } 49 | \references{ 50 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 51 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 52 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 53 | } 54 | \author{ 55 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 56 | } 57 | -------------------------------------------------------------------------------- /man/MuiaovMcomper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MuiaovMcomper.R 3 | \name{MuiaovMcomper} 4 | \alias{MuiaovMcomper} 5 | \title{Perform ANOVA and run multiple comparisons for more sets of data} 6 | \usage{ 7 | MuiaovMcomper(data = data_wt, num = c(4:6), method_Mc = "Tukey") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{num}{index col which to test normality and homogeneity} 13 | 14 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Perform ANOVA and run multiple comparisons for more sets of data 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 25 | # utput result for multiple comparison results 26 | result 27 | } 28 | \references{ 29 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 30 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 31 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 32 | } 33 | \author{ 34 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 35 | } 36 | -------------------------------------------------------------------------------- /man/MuiaovMcomper2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/util.R 3 | \name{MuiaovMcomper2} 4 | \alias{MuiaovMcomper2} 5 | \title{Perform ANOVA and run multiple comparisons for more sets of data and order in order to mean value of treatment} 6 | \usage{ 7 | MuiaovMcomper2(data = data_wt, num = c(4:6), method_Mc = "Tukey") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{num}{index col which to test normality and homogeneity} 13 | 14 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Perform ANOVA and run multiple comparisons for more sets of data and order in order to mean value of treatment 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result = MuiaovMcomper(data = data_wt,num = c(4:6),method_Mc = "Tukey") 25 | # utput result for multiple comparison results 26 | result 27 | } 28 | \references{ 29 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 30 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 31 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 32 | } 33 | \author{ 34 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{2018203048@njau.edu.cn} 35 | } 36 | -------------------------------------------------------------------------------- /man/NorNorCVTest.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NorNorCVTest.R 3 | \name{NorNorCVTest} 4 | \alias{NorNorCVTest} 5 | \title{Test normality and homogeneity of variance of Input data} 6 | \usage{ 7 | NorNorCVTest(data = data_wt, i = 4, method_cv = "leveneTest", ...) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method_cv}{which method to test variance, included "leveneTest","bartlett.test".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Test normality and homogeneity of variance of Input data 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | NorNorCVTest(data = data_wt, i= 4) 25 | } 26 | \references{ 27 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 28 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 29 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 30 | } 31 | \author{ 32 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 33 | } 34 | -------------------------------------------------------------------------------- /man/SingleStat.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/SingleStat.R 3 | \name{SingleStat} 4 | \alias{SingleStat} 5 | \title{A complete single-factor difference analysis process for single col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method.} 6 | \usage{ 7 | SingleStat( 8 | data = data_wt, 9 | plot = "bar", 10 | method_Mc = "Tukey", 11 | i = 4, 12 | sig_show = "abc" 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data.Enter the data frame, the first column is the sample number, 17 | the second column is the group, note that the group label must be set to group, and the third column and later are the 18 | indicators for measurement or collection.} 19 | 20 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 21 | 22 | \item{sig_show}{Distinctive display, "abc" or "line"} 23 | 24 | \item{num}{col index wtich need to test} 25 | 26 | \item{method_cv}{which method to test variance, included "leveneTest","bartlett.test"} 27 | } 28 | \value{ 29 | list 30 | } 31 | \description{ 32 | A complete single-factor difference analysis process for single col data, including normal test, homogeneity analysis of variance, selection of variance analysis or non-parametric test, selection of candidate d visualization method. 33 | } 34 | \examples{ 35 | # data(data_wt) 36 | result = SingleStat(data = data_wt,plot = "bar",method_Mc = "Tukey",i= 4,sig_show ="abc") 37 | result[[1]] 38 | } 39 | \references{ 40 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 41 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 42 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 43 | } 44 | \author{ 45 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 46 | } 47 | -------------------------------------------------------------------------------- /man/aovMcomper.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/aovMcomper.R 3 | \name{aovMcomper} 4 | \alias{aovMcomper} 5 | \title{Perform ANOVA and run multiple comparisons} 6 | \usage{ 7 | aovMcomper(data = data_wt, i = 3, method_Mc = "Tukey") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Perform ANOVA and run multiple comparisons 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result= aovMcomper (data = data_wt, i= 5,method_Mc = "Tukey") 25 | # utput result for multiple comparison results 26 | result[[1]] 27 | } 28 | \references{ 29 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 30 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 31 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 32 | } 33 | \author{ 34 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 35 | } 36 | -------------------------------------------------------------------------------- /man/aovMcomper2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/util.R 3 | \name{aovMcomper2} 4 | \alias{aovMcomper2} 5 | \title{Perform ANOVA and run multiple comparisons and order in order to mean value of treatment} 6 | \usage{ 7 | aovMcomper2(data = data_wt, i = 3, method_Mc = "Tukey") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{method_Mc}{which specify the method of multiple comparisons.included:"Tukey","LSD","SNK","Duncan","scheffe","scheffe".} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Perform ANOVA and run multiple comparisons and order in order to mean value of treatment 21 | } 22 | \examples{ 23 | # data(data_wt) 24 | result= aovMcomper2 (data = data_wt, i= 5,method_Mc = "Tukey") 25 | # utput result for multiple comparison results 26 | result[[1]] 27 | } 28 | \references{ 29 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 30 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 31 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 32 | } 33 | \author{ 34 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 35 | } 36 | -------------------------------------------------------------------------------- /man/aovMuiBarPlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BarP.R 3 | \name{aovMuiBarPlot} 4 | \alias{aovMuiBarPlot} 5 | \title{Variance test or non-parametric test results visualization, using histogram} 6 | \usage{ 7 | aovMuiBarPlot( 8 | data = data_wt, 9 | i = 3, 10 | sig_show = "line", 11 | result = result, 12 | ns = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{i}{col index wtich need to test} 19 | 20 | \item{sig_show}{Distinctive display, "abc" or "line"} 21 | 22 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 23 | 24 | \item{ns}{Logical value, whether to display insignificant marks} 25 | } 26 | \value{ 27 | list 28 | } 29 | \description{ 30 | Variance test or non-parametric test results visualization, using histogram 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = KwWlx(data = data_wt, i= 4) 35 | PlotresultBar = aovMuiBarPlot(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 36 | # utput result 37 | PlotresultBar[[1]] 38 | } 39 | \references{ 40 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 41 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 42 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 43 | } 44 | \author{ 45 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 46 | } 47 | -------------------------------------------------------------------------------- /man/aovMuiBoxBarP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BoxBarP.R 3 | \name{aovMuiBoxBarP} 4 | \alias{aovMuiBoxBarP} 5 | \title{Variance test or non-parametric test results visualization, using boxbar} 6 | \usage{ 7 | aovMuiBoxBarP( 8 | data = data_wt, 9 | i = 3, 10 | sig_show = "line", 11 | result = result, 12 | ns = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{i}{col index wtich need to test} 19 | 20 | \item{sig_show}{Distinctive display, "abc" or "line"} 21 | 22 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 23 | 24 | \item{ns}{Logical value, whether to display insignificant marks} 25 | } 26 | \value{ 27 | list 28 | } 29 | \description{ 30 | Variance test or non-parametric test results visualization, using boxbar 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = KwWlx(data = data_wt, i= 4) 35 | PlotresultBox = aovMuiBoxBarP(data = data_wt, i= 3,sig_show ="abc",result = result[[1]]) 36 | # utput result 37 | result[[1]] 38 | 39 | } 40 | \references{ 41 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 42 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 43 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 44 | } 45 | \author{ 46 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 47 | } 48 | -------------------------------------------------------------------------------- /man/aovMuiBoxP.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BoxP.R 3 | \name{aovMuiBoxP} 4 | \alias{aovMuiBoxP} 5 | \title{Variance test or non-parametric test results visualization, using boxplot} 6 | \usage{ 7 | aovMuiBoxP( 8 | data = data_wt, 9 | i = 3, 10 | sig_show = "line", 11 | result = result, 12 | ns = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{i}{col index wtich need to test} 19 | 20 | \item{sig_show}{Distinctive display, "abc" or "line"} 21 | 22 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 23 | 24 | \item{ns}{Logical value, whether to display insignificant marks} 25 | } 26 | \value{ 27 | data frame 28 | } 29 | \description{ 30 | Variance test or non-parametric test results visualization, using boxplot 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = KwWlx(data = data_wt, i= 4) 35 | PlotresultBox = aovMuiBoxP(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 36 | # utput result 37 | p = PlotresultBox[[1]] 38 | p 39 | } 40 | \references{ 41 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 42 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 43 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 44 | } 45 | \author{ 46 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 47 | } 48 | -------------------------------------------------------------------------------- /man/aovMuiBoxP2.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/Boxp2.R 3 | \name{aovMuiBoxP2} 4 | \alias{aovMuiBoxP2} 5 | \title{Variance test or non-parametric test results visualization, using boxplot paired line show pair com...} 6 | \usage{ 7 | aovMuiBoxP2( 8 | data = data_wt, 9 | i = 3, 10 | sig_show = "line", 11 | result = result, 12 | ns = FALSE 13 | ) 14 | } 15 | \arguments{ 16 | \item{data}{a data.frame contain the input data} 17 | 18 | \item{i}{for col id or colames} 19 | 20 | \item{sig_show}{Distinctive display, "abc" or "line"} 21 | 22 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 23 | 24 | \item{ns}{Logical value, whether to display insignificant marks} 25 | } 26 | \value{ 27 | data frame 28 | } 29 | \description{ 30 | Variance test or non-parametric test results visualization, using boxplot paired line show pair com... 31 | } 32 | \examples{ 33 | # data(data_wt) 34 | result = KwWlx2(data = data_wt, i= 4) 35 | PlotresultBox = aovMuiBoxP2(data = data_wt, i= 4,sig_show ="abc",result = result[[1]]) 36 | # utput result 37 | p = PlotresultBox[[1]] 38 | p 39 | } 40 | \references{ 41 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 42 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 43 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 44 | } 45 | \author{ 46 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 47 | } 48 | -------------------------------------------------------------------------------- /man/ord_sig.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ord_sig.R 3 | \name{ord_sig} 4 | \alias{ord_sig} 5 | \title{Reverse the significance level of letter marks} 6 | \usage{ 7 | ord_sig(data = da, ID = "groups") 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{ID}{col index wtich need to reverse significance level,if NULL was marked, would transform to each col.} 13 | } 14 | \value{ 15 | data.frame 16 | } 17 | \description{ 18 | Reverse the significance level of letter marks 19 | } 20 | \examples{ 21 | # data(data_wt) 22 | result = KwWlx(data = data_wt, i= 4) 23 | datord <- ord_sig(data = result[[1]],ID = NULL) 24 | } 25 | \references{ 26 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 27 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 28 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 29 | } 30 | \author{ 31 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} 32 | } 33 | -------------------------------------------------------------------------------- /man/value_stackBar.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/value_stackBar.R 3 | \name{value_stackBar} 4 | \alias{value_stackBar} 5 | \title{Stacked histograms add error bars, marked by significance} 6 | \usage{ 7 | value_stackBar(data = data, i, result = result, add_abc = TRUE) 8 | } 9 | \arguments{ 10 | \item{data}{a data.frame contain the input data} 11 | 12 | \item{i}{col index wtich need to test} 13 | 14 | \item{result}{output from aovMcomper or KwWlx. You can also import result calculated from other software (a data frame)} 15 | 16 | \item{add_abc}{add sig abc T or F} 17 | 18 | \item{errbar}{add a distinctive label, TRUE or FEASE could be selected} 19 | } 20 | \value{ 21 | list 22 | } 23 | \description{ 24 | Stacked histograms add error bars, marked by significance 25 | } 26 | \examples{ 27 | # data(data_wt) 28 | result = MuiKwWlx(data = data_wt,num = c(4,9,8)) 29 | res <- value_stackBar(data = data_wt,i = c(4,9,8) ,result = result, 30 | add_abc = TRUE) 31 | res[[1]] 32 | } 33 | \references{ 34 | Yuan J, Zhao J, Wen T, Zhao M, Li R, Goossens P, Huang Q, Bai Y, Vivanco JM, Kowalchuk GA, Berendsen RL, Shen Q 35 | Root exudates drive the soil-borne legacy of aboveground pathogen infection 36 | Microbiome 2018,DOI: \url{doi: 10.1186/s40168-018-0537-x} 37 | } 38 | \author{ 39 | Contact: Tao Wen \email{2018203048@njau.edu.cn} Jun Yuan \email{junyuan@njau.edu.cn} PengHao Xie \email{2019103106@njau.edu.cn} 40 | } 41 | --------------------------------------------------------------------------------