Skip to content

Commit

Permalink
Merge pull request #180 from mixOmicsTeam/issue-120
Browse files Browse the repository at this point in the history
Fix for Issue #120
  • Loading branch information
aljabadi authored May 2, 2022
2 parents ceebc84 + 9512ea4 commit d18f41c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
19 changes: 17 additions & 2 deletions R/plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ plotLoadings.mixo_pls <-
if (length(block) == 1 & !is.null(name.var))
name.var = list(name.var = name.var)

contrib.df <- list()

for (i in 1 : length(block))
{
res = get.loadings.ndisplay(object = object, comp = comp, block = block[i], name.var = name.var[[i]], name.var.complete = name.var.complete, ndisplay = ndisplay)
Expand Down Expand Up @@ -204,8 +206,12 @@ plotLoadings.mixo_pls <-
} else if (length(block) > 1 & !missing(subtitle)) {
title(paste(subtitle[i]), line=0, cex.main = size.subtitle)
}

contrib.df <- c(contrib.df, list(df))
}

names(contrib.df) <- block

if (length(block) > 1 & !is.null(title))
title(title, outer=TRUE, line = -2, cex.main = size.title)

Expand All @@ -215,7 +221,7 @@ plotLoadings.mixo_pls <-
par(mar = omar) #reset mar

# return the contribution matrix
return(invisible(df))
return(invisible(contrib.df))
}

#' @rdname plotLoadings
Expand Down Expand Up @@ -391,6 +397,9 @@ plotLoadings.mixo_plsda <-
if (length(block) == 1 & !is.null(name.var))
name.var = list(name.var = name.var)


contrib.df <- list()

for (i in 1 : length(block))
{
res = get.loadings.ndisplay(object = object, comp = comp, block = block[i], name.var = name.var[[i]], name.var.complete = name.var.complete, ndisplay = ndisplay)
Expand Down Expand Up @@ -457,9 +466,14 @@ plotLoadings.mixo_plsda <-
title = paste(legend.title),
cex = size.legend)
}

contrib.df <- c(contrib.df, list(df))
} # end if plot
}

names(contrib.df) <- block


if(plot) # overall title and reset par if needed
{
# legend
Expand All @@ -473,7 +487,7 @@ plotLoadings.mixo_plsda <-
}

# return the contribution matrix
return(invisible(df))
return(invisible(contrib.df)) # df
}# end contrib missing
}

Expand Down Expand Up @@ -1253,6 +1267,7 @@ get.contrib.df <- function(Y,
method.group[[k]] = tapply(X[, k], Y, method, na.rm=TRUE) #method is either mean or median
# determine which group has the highest mean/median
which.contrib[k, 1:nlevels(Y)] = (method.group[[k]]) == get(contrib)((method.group[[k]]), na.rm=TRUE) # contrib is either min or max

}

# we also add an output column indicating the group that is max
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-plotLoadings.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test_that("plotLoadings.spls works", code = {

pl_res <- plotLoadings(toxicity.spls)

expect_is(pl_res, "data.frame")
expect_is(pl_res, "list")

})

Expand All @@ -23,7 +23,7 @@ test_that("plotLoadings.splsda works", code = {

pl_res <- plotLoadings(splsda.liver, comp = 1, method = 'median')

expect_is(pl_res, "data.frame")
expect_is(pl_res, "list")

})

Expand All @@ -42,7 +42,7 @@ test_that("plotLoadings.block.splsda works", code = {

pl_res <- plotLoadings(nutrimouse.sgccda,block=2)

expect_is(pl_res, "data.frame")
expect_is(pl_res, "list")

})

Expand All @@ -55,7 +55,7 @@ test_that("plotLoadings.mint.splsda works", code = {
res = mint.splsda(X = data, Y = type.id, ncomp = 3, keepX = c(10,5,15), study = exp)
pl_res <- plotLoadings(res, contrib = "max")

expect_is(pl_res, "data.frame")
expect_is(pl_res, "list")

})

Expand Down

0 comments on commit d18f41c

Please sign in to comment.