Skip to content

Commit

Permalink
Version 1.04
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKim5 committed Jul 16, 2021
1 parent 6756959 commit 3be15fd
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 29 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 4 additions & 4 deletions R/AS_barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions R/AS_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions R/AS_dotplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions R/Allstats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
66 changes: 66 additions & 0 deletions R/NMDS.R
Original file line number Diff line number Diff line change
@@ -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")
}}
6 changes: 0 additions & 6 deletions man/AS_barplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/AS_boxplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/AS_dotplot.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions man/Allstats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
38 changes: 38 additions & 0 deletions man/NMDS.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3be15fd

Please sign in to comment.