Skip to content
Snippets Groups Projects
Commit 78f57cfb authored by Otto, Dr. Saskia's avatar Otto, Dr. Saskia
Browse files

fixed bug with missing labels

parent a92c549b
No related branches found
No related tags found
No related merge requests found
......@@ -21,10 +21,10 @@
#' @seealso \url{https://doi.org/10.1051/alr/2009020}
#' @examples
#' df <- data.frame(variable1variabl = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20))
#' mafa(x = df, time = 1981:2000, nreal = 10)
#' df <- matrix(rnorm(100), ncol = 5)
#' colnames(df) <- letters[1:5]
#' mafa(df)
#' mafa(x = df, time = 1981:2000)
#' df <- matrix(rnorm(1000), ncol = 50)
#' colnames(df) <- paste0(letters[1:25], rep(1:2,each = 25))
#' mafa(df, contr_var = 10)
#'
mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var = NULL){
......@@ -123,12 +123,12 @@ mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var
# choose top contr_var
choose <- rev(order(abs(maf_rot)))[1:contr_var]
maf_rot <- maf_rot[choose]
vars <- vars[choose]
vars_j <- vars[choose]
# sort
ord <- order(maf_rot)
maf_rot <- maf_rot[ord]
vars <- vars[ord]
nvc <- length(vars)
vars_j <- vars_j[ord]
nvc <- length(vars_j)
mr_pos <- which(maf_rot > 0)
mr_neg <- which(maf_rot < 0)
fac <- 2
......@@ -141,10 +141,10 @@ mafa <- function(x, time = NULL, nreal = 1000, nmafs = 3, seed = NULL, contr_var
Col <- rep(1, nvc)
Col[seq(1, nvc, 1)[abs(maf_rot) == max(abs(maf_rot))]] <- 3
if (length(mr_pos) > 0) {
text(maf_rot[mr_pos], seq(0.5, nvc-.5, 1)[mr_pos], vars[mr_pos], cex = .9, col = Col[mr_pos], pos = 4)
text(maf_rot[mr_pos], seq(0.5, nvc-.5, 1)[mr_pos], vars_j[mr_pos], cex = .9, col = Col[mr_pos], pos = 4)
}
if (length(mr_neg) > 0) {
text(maf_rot[mr_neg], seq(0.5, nvc-.5, 1)[mr_neg], vars[mr_neg], cex = .9, col = Col[mr_neg], pos = 2)
text(maf_rot[mr_neg], seq(0.5, nvc-.5, 1)[mr_neg], vars_j[mr_neg], cex = .9, col = Col[mr_neg], pos = 2)
}
......
......@@ -31,11 +31,11 @@ the part of the variables which is the most continuous in time.
The function for this code is adopted from Wollez et al. 2009 (\url{https://doi.org/10.1051/alr/2009020})
}
\examples{
df <- data.frame(variable1 = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20))
df <- data.frame(variable1variabl = 1:20, variable2= rnorm(20, 100, 30), variable3 = 1:20 + rnorm(20))
mafa(x = df, time = 1981:2000)
df <- matrix(rnorm(100), ncol = 5)
colnames(df) <- letters[1:5]
mafa(df)
df <- matrix(rnorm(1000), ncol = 50)
colnames(df) <- paste0(letters[1:25], rep(1:2,each = 25))
mafa(df, contr_var = 10)
}
\seealso{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment