diff --git a/DESCRIPTION b/DESCRIPTION index eeba60e..96774e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: LMSstat Title: AUTOMATION OF STATISTICAL TESTS WITH AN IDENTICAL DATA INPUT. -Version: 1.0.3 +Version: 1.0.4 Authors@R: person(given = "CHANG-HO", family = "KIM", diff --git a/R/AS_barplot.R b/R/AS_barplot.R index 65ec61d..9393d30 100644 --- a/R/AS_barplot.R +++ b/R/AS_barplot.R @@ -16,10 +16,10 @@ #' @return ggbarplot #' @export #' -#' @examples D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -#' Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -#' Test<-Allstats(Datas) -#' AS_barplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) +#' @example data(Data) +#' Test<-Allstats(Data) +#' AS_barplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099")) +#' AS_barplot<-function(data, asterisk="t_test", significant_variable_only=F, diff --git a/R/AS_boxplot.R b/R/AS_boxplot.R index e0721df..82164e9 100644 --- a/R/AS_boxplot.R +++ b/R/AS_boxplot.R @@ -16,9 +16,8 @@ #' @return ggboxplot #' @export #' -#' @examples D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -#' Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -#' Test<-Allstats(Datas) +#' @examples data(Data) +#' Test<-Allstats(Data) #' AS_boxplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) AS_boxplot<-function(data, asterisk="t_test", diff --git a/R/AS_dotplot.R b/R/AS_dotplot.R index 071bc20..e9f633a 100644 --- a/R/AS_dotplot.R +++ b/R/AS_dotplot.R @@ -16,9 +16,8 @@ #' @return ggdotplot #' @export #' -#' @examples D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -#' Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -#' Test<-Allstats(Datas) +#' @examples data(Data) +#' Test<-Allstats(Data) #' AS_dotplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) AS_dotplot<-function(data, asterisk="t_test", diff --git a/R/Allstats.R b/R/Allstats.R index cbef2ea..f2fe5b5 100644 --- a/R/Allstats.R +++ b/R/Allstats.R @@ -7,9 +7,8 @@ #' @return List including Result Matrix of p-values, converted datas. #' @export #' -#' @examples D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -#' Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -#' Allstats(Datas) +#' @examples data(Data) +#' Result<-Allstats(Data) #' #' Allstats<-function (Data, Adjust_p_value = T, Adjust_method = "BH") diff --git a/R/NMDS.R b/R/NMDS.R new file mode 100644 index 0000000..7941ce8 --- /dev/null +++ b/R/NMDS.R @@ -0,0 +1,66 @@ +#' Automatically save NMDS plots for the selected dimension metrics +#' +#' @param Data +#' @param methods #methods<- c("manhattan", "euclidean", "canberra", "clark", "bray", "kulczynski", "jaccard", "gower", "altGower", "morisita", "horn", "raup", "binomial", "mahalanobis", "chisq","chord") #can be any distance c["manhattan", "euclidean", "canberra", "clark", "bray", "kulczynski", "jaccard", "gower", "altGower", "morisita", "horn", "mountford", "raup", "binomial", "chao", "cao", "mahalanobis", "chisq","chord"] +#' @param color colors used for ggplots.color=c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") +#' @param legend_position legend position "none","left","right","bottom","top" +#' @param fig_width figure size +#' @param fig_height figure size +#' +#' @return NMDS plot +#' @export +#' +#' @examples data(Data) +#' NMDS(Data,methods = c("euclidian","manhattan","bray")) + +NMDS<-function(Data, + methods=c("euclidean","bray"), + color = c("#FF3300","#660099","#FFCC00","#99CC00","#0066CC","#FF6600"), + legend_position = "bottom", + fig_width = 24, + fig_height = 20 + ){ + ifelse(!dir.exists(file.path(getwd(), "NMDS")), dir.create(file.path(getwd(), "NMDS")), FALSE) + colnames(Data) <- Data[1, ] + Data <- Data[-1, -2] + Data<-Data %>% dplyr::arrange(Group) + rownames(Data)<-Data[,1];Data<-Data[,-1] + Data[,2:ncol(Data)]<-sapply(Data[,2:ncol(Data)],function(x) as.numeric(x)) + NMDS_Data_input<-Data#subset samples of interest, columns: Group(Male, Female etc)+metabolite, rownames : sample names + NMDS_Data_input[,1]<-as.factor(NMDS_Data_input[,1]) # Group as factors + for(method in methods){ + Dist_Met<-as.matrix(vegan::vegdist(NMDS_Data_input[,2:ncol(NMDS_Data_input)],method = method)) + NMDS=vegan::metaMDS(Dist_Met,k = 2,trymax = 2000)#Bray curtis + x_y_coord<-as.data.frame(vegan::scores(NMDS,display = "sites")) + x_y_coord_G <- cbind(x_y_coord, NMDS_Data_input$Group) + colnames(x_y_coord_G)[3]<-"Group" + M_p_value<-vegan::adonis2(Dist_Met~Group, + method = method, + by = NULL, + data = x_y_coord_G)[["Pr(>F)"]][1] #Model P_Value + ggplot2::ggplot() + + ggplot2::geom_point(data = x_y_coord_G, ggplot2::aes(x = NMDS1, y = NMDS2, + color = Group), size = 3)+ + ggplot2::theme_minimal() + + ggplot2::scale_color_manual(values = color)+ + ggplot2::theme(plot.title=ggplot2::element_text(size=10, + face="bold", + color="Black", + hjust=0.5, + lineheight=1.2), # title + plot.subtitle=ggplot2::element_text(size=15, + hjust=0.5), # subtitle + plot.caption=ggplot2::element_text(size=15), # caption + axis.title.x=ggplot2::element_text(vjust=0, + size=10), # X axis title + axis.title.y=ggplot2::element_text(size=10), # Y axis title + legend.position = legend_position)+ + ggplot2::stat_ellipse(ggplot2::aes(x=x_y_coord_G$NMDS1, + y=x_y_coord_G$NMDS2,color=x_y_coord_G$Group), + type = "norm")+ + ggplot2::ggtitle(paste(method,"index/distance, ","Stress Level : ",NMDS$stress,"Model_p_value",M_p_value)) + ggplot2::ggsave(paste(method,"NMDS.png",sep = "_"), + path=paste0(getwd(),"/NMDS"), + height = fig_height, + width = fig_width,units = "cm") + }} \ No newline at end of file diff --git a/man/AS_barplot.Rd b/man/AS_barplot.Rd index 63268a4..8168e83 100644 --- a/man/AS_barplot.Rd +++ b/man/AS_barplot.Rd @@ -50,9 +50,3 @@ ggbarplot \description{ Automatically save barplots for all metabolites including asterisks for significance. } -\examples{ -D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -Test<-Allstats(Datas) -AS_barplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) -} diff --git a/man/AS_boxplot.Rd b/man/AS_boxplot.Rd index 21f0a7b..26d6a41 100644 --- a/man/AS_boxplot.Rd +++ b/man/AS_boxplot.Rd @@ -51,8 +51,7 @@ ggboxplot Automatically save boxplots for all metabolites including asterisks for significance. } \examples{ -D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -Test<-Allstats(Datas) +data(Data) +Test<-Allstats(Data) AS_boxplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) } diff --git a/man/AS_dotplot.Rd b/man/AS_dotplot.Rd index 889dd8d..04a96c9 100644 --- a/man/AS_dotplot.Rd +++ b/man/AS_dotplot.Rd @@ -51,8 +51,7 @@ ggdotplot Automatically save dotplots for all metabolites including asterisks for significance. } \examples{ -D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -Test<-Allstats(Datas) +data(Data) +Test<-Allstats(Data) AS_dotplot(Test,asterisk = "Dunn",significant_variable_only = F,color = c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099") ) } diff --git a/man/Allstats.Rd b/man/Allstats.Rd index 6ffc461..66d0070 100644 --- a/man/Allstats.Rd +++ b/man/Allstats.Rd @@ -20,9 +20,8 @@ List including Result Matrix of p-values, converted datas. Automatically processes T-test, U-test, Anova, Scheffe(Anova Post-Hoc), Krukal Wallis, Dunn-test(BH adjusted,(Kurkal Wallis Post-Hoc)) while allowing adjustment of FDR } \examples{ -D<-as.data.frame(cbind(LETTERS,rep(1,26),c(rep("A",7),rep("B",6),rep("C",13)),runif(26),runif(26))) -Datas<-rbind(c("Sample","Multilevel","Group","some metabolite1","some metabolite2"),D) -Allstats(Datas) +data(Data) +Result<-Allstats(Data) } diff --git a/man/NEWS.Rd b/man/NEWS.Rd index 96c8719..a40e0c3 100644 --- a/man/NEWS.Rd +++ b/man/NEWS.Rd @@ -28,3 +28,8 @@ \item AS_dotplot Optimization for paper ready figures } } +\section{Changes in version 1.0.4,(July 2021)}{ + \itemize{ + \item NMDS added + } +} diff --git a/man/NMDS.Rd b/man/NMDS.Rd new file mode 100644 index 0000000..c6a1158 --- /dev/null +++ b/man/NMDS.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/NMDS.R +\name{NMDS} +\alias{NMDS} +\title{Automatically save NMDS plots for the selected dimension metrics} +\usage{ +NMDS( + Data, + methods = c("euclidean", "bray"), + color = c("#FF3300", "#660099", "#FFCC00", "#99CC00", "#0066CC", "#FF6600"), + legend_position = "bottom", + fig_width = 24, + fig_height = 20 +) +} +\arguments{ +\item{Data}{} + +\item{methods}{#methods<- c("manhattan", "euclidean", "canberra", "clark", "bray", "kulczynski", "jaccard", "gower", "altGower", "morisita", "horn", "raup", "binomial", "mahalanobis", "chisq","chord") #can be any distance c\link{"manhattan", "euclidean", "canberra", "clark", "bray", "kulczynski", "jaccard", "gower", "altGower", "morisita", "horn", "mountford", "raup", "binomial", "chao", "cao", "mahalanobis", "chisq","chord"}} + +\item{color}{colors used for ggplots.color=c("#FF3300","#FF6600","#FFCC00","#99CC00","#0066CC","#660099")} + +\item{legend_position}{legend position "none","left","right","bottom","top"} + +\item{fig_width}{figure size} + +\item{fig_height}{figure size} +} +\value{ +NMDS plot +} +\description{ +Automatically save NMDS plots for the selected dimension metrics +} +\examples{ +data(Data) +NMDS(Data,methods = c("euclidian","manhattan","bray")) +}