diff --git a/NAMESPACE b/NAMESPACE index 54c0e1f1b2ff02ae5f1622d53479c3a292c62f5a..5732095518652d0c06f5e6cd231386a28df51337 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,8 @@ importFrom(ggplot2,geom_point) importFrom(ggplot2,ggplot) importFrom(ggplot2,ggtitle) importFrom(ggplot2,scale_color_manual) +importFrom(ggplot2,xlab) +importFrom(ggplot2,ylab) importFrom(stats,dnorm) importFrom(stats,na.omit) importFrom(stats,quantile) diff --git a/R/graph_functions.R b/R/graph_functions.R index 765abab51ce08d15c8b5e961d784a7a643838b58..aa919d1296e705448c9258ccd32f658e79507739 100644 --- a/R/graph_functions.R +++ b/R/graph_functions.R @@ -8,6 +8,8 @@ #' @param Yvar char, variable which was analysed in the data.frame datain #' @param Ident char, column name of the individual id to be analyzed #' @param title char, a graph title +#' @param labelX char, a label for x-axis +#' @param labelY char, a label for y-axis #' #' @details The produced graphic can be, according to typeG: #' \describe{ @@ -20,7 +22,7 @@ #' } #' #' @importFrom ggplot2 aes aes_string ggplot geom_point geom_line -#' @importFrom ggplot2 scale_color_manual ggtitle +#' @importFrom ggplot2 scale_color_manual ggtitle xlab ylab #' @return a ggplot2 graphic #' @export #' @@ -49,7 +51,9 @@ #' #' # flags are qualitative #' kfino_plot(resuin=resu2,typeG="quali", -#' Tvar="Day",Yvar="Poids",Ident="IDE") +#' Tvar="Day",Yvar="Poids",Ident="IDE", +#' title="kfino spring1", +#' labelX="Time (day)",labelY="Weight (kg)") #' #' # flags are quantitative #' kfino_plot(resuin=resu2,typeG="quanti", @@ -63,7 +67,9 @@ kfino_plot<-function(resuin, Tvar, Yvar, Ident, - title=NULL){ + title=NULL, + labelX=NULL, + labelY=NULL){ # Existence check if (is.null(resuin[[1]])) { @@ -87,6 +93,9 @@ kfino_plot<-function(resuin, tp.title1<-paste0(title," - ",myIDE) tp.title2<-paste0(title," - ",myIDE) } + + if (is.null(labelX)) labelX<-Tvar + if (is.null(labelY)) labelY<-Yvar # graphics if (typeG == "quali"){ @@ -100,13 +109,13 @@ kfino_plot<-function(resuin, color="green") + scale_color_manual(values = c("KO"="purple", "OK" = "black", "OOR"="red")) + - ggtitle(tp.title1) + ggtitle(tp.title1) + xlab(labelX) + ylab(labelY) } else { g1<-ggplot(tp,aes_string(x=Tvar))+ geom_point( aes_string(y=Yvar,color="flag")) + scale_color_manual(values = c("KO"="purple", "OK" = "black", "OOR"="red")) + - ggtitle(tp.title1) + ggtitle(tp.title1) + xlab(labelX) + ylab(labelY) } return(g1) } else if (typeG == "quanti"){ @@ -118,7 +127,7 @@ kfino_plot<-function(resuin, color="green") + geom_line(data=tp[!is.na(tp$prediction),], aes(y=.data$upr), color="green") + - ggtitle(tp.title1) + ggtitle(tp.title1) + xlab(labelX) + ylab(labelY) return(g1) } } else if (typeG == "prediction"){ @@ -129,7 +138,7 @@ kfino_plot<-function(resuin, geom_line(data=tp2, aes(y=.data$prediction)) + geom_line(data=tp2, aes(y=.data$lwr),color="green") + geom_line(data=tp2, aes(y=.data$upr),color="green") + - ggtitle(tp.title2) + ggtitle(tp.title2) + xlab(labelX) + ylab(labelY) return(g1) } } diff --git a/man/kfino_plot.Rd b/man/kfino_plot.Rd index 1c86f0ad103d253fb2c4bc28ec0062353c8d2092..48943572c1f86f2e7fdce10af8eabc8c6c72017f 100644 --- a/man/kfino_plot.Rd +++ b/man/kfino_plot.Rd @@ -4,7 +4,16 @@ \alias{kfino_plot} \title{kfino_plot a graphical function for the result of a kfino run} \usage{ -kfino_plot(resuin, typeG, Tvar, Yvar, Ident, title = NULL) +kfino_plot( + resuin, + typeG, + Tvar, + Yvar, + Ident, + title = NULL, + labelX = NULL, + labelY = NULL +) } \arguments{ \item{resuin}{a list resulting of the kfino algorithm} @@ -20,6 +29,10 @@ qualitative or quantitative display) or prediction. must be \item{Ident}{char, column name of the individual id to be analyzed} \item{title}{char, a graph title} + +\item{labelX}{char, a label for x-axis} + +\item{labelY}{char, a label for y-axis} } \value{ a ggplot2 graphic @@ -63,7 +76,9 @@ resu2<-kfino_fit(datain=spring1, # flags are qualitative kfino_plot(resuin=resu2,typeG="quali", - Tvar="Day",Yvar="Poids",Ident="IDE") + Tvar="Day",Yvar="Poids",Ident="IDE", + title="kfino spring1", + labelX="Time (day)",labelY="Weight (kg)") # flags are quantitative kfino_plot(resuin=resu2,typeG="quanti", diff --git a/tests/testthat/test-outputAlgo.R b/tests/testthat/test-outputAlgo.R index d2b30e5530f72268c151cba86f960298be5dc7b3..d3a1992ce66760ca6c6d0e80d1af3442c8f28545 100644 --- a/tests/testthat/test-outputAlgo.R +++ b/tests/testthat/test-outputAlgo.R @@ -73,7 +73,7 @@ test_that("KBO_L - likelihood - computed correctly", { sigma2_pp=5, K=2, seqp=seq(0.5,0.7,0.1)) - resu<-KBO_L(param=param2,Y=Y,Tps=Tps,N=N,dix=6,kappaOpt=7) + resu<-KBO_L(param=param2,Y=Y,Tps=Tps,N=N,scalingC=6,kappaOpt=7) expect_equal(as.vector(resu),0.00490257592)