Skip to content

Commit

Permalink
named group usage in S3methods for invariance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChristensen committed Aug 13, 2024
1 parent f88c6e3 commit 0b901d3
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions R/invariance.R
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,13 @@ print.invariance <- function(x, pairs = list(), ...)
pairs_sequence <- seq_len(total_pairs)

# Create combination of pairs
possible_pairs <- combn(length(x$groups$EGA), 2, simplify = FALSE)
possible_pairs <- combn(names(x$groups$EGA), 2, simplify = FALSE)

# Check for pairs
input_pairs <- length(pairs) == 0

# Check for missing pairs
if(length(pairs) == 0){
if(input_pairs){
pairs <- possible_pairs
}

Expand Down Expand Up @@ -729,7 +732,12 @@ print.invariance <- function(x, pairs = list(), ...)
}

# Print significance codes
cat("Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 'n.s.' 1\n")
cat("Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 'n.s.' 1\n\n")

# Let user know about print
if(input_pairs && total_pairs > 1){
cat("Use the argument 'pairs = list()' for individual paired results using `c()` inside `list()` (for multiple pairs, use `c()` inside `list()` for each pair).\n")
}

}

Expand Down Expand Up @@ -781,7 +789,7 @@ summary.invariance <- function(object, ...)
}

# Let user know about print
cat("Use `print()` and the argument 'pairs' for detailed results.\n")
cat("Use `print()` for more detailed results.\n")

}

Expand Down Expand Up @@ -872,10 +880,13 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value
pairs_sequence <- seq_len(total_pairs)

# Create combination of pairs
possible_pairs <- combn(length(x$groups$EGA), 2, simplify = FALSE)
possible_pairs <- combn(names(x$groups$EGA), 2, simplify = FALSE)

# Check for pairs
input_pairs <- length(pairs) == 0

# Check for missing pairs
if(length(pairs) == 0){
if(input_pairs){
pairs <- possible_pairs
}else if(length(pairs) > 6){ # Don't do more than 6 comparisons (equivalent to 4 groups)

Expand Down Expand Up @@ -1070,7 +1081,7 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value
ggpubr::ggarrange(
first_group, second_group,
ncol = 2, nrow = 1,
labels = names(x$groups$EGA)[possible_pairs[[pair_index[[index]]]]],
labels = possible_pairs[[pair_index[[index]]]],
legend = "bottom",
common.legend = FALSE
)
Expand All @@ -1091,7 +1102,7 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value
ggpubr::ggarrange(
first_group, second_group,
ncol = 2, nrow = 1,
labels = names(x$groups$EGA)[possible_pairs[[pair_index[[index]]]]],
labels = possible_pairs[[pair_index[[index]]]],
legend = "none"
)
)
Expand Down Expand Up @@ -1201,7 +1212,7 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value
ggpubr::ggarrange(
first_group, second_group,
ncol = 2, nrow = 1,
labels = names(x$groups$EGA)[possible_pairs[[pair_index[[index]]]]],
labels = possible_pairs[[pair_index[[index]]]],
legend = "bottom",
common.legend = FALSE
)
Expand All @@ -1222,7 +1233,7 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value
ggpubr::ggarrange(
first_group, second_group,
ncol = 2, nrow = 1,
labels = names(x$groups$EGA)[possible_pairs[[pair_index[[index]]]]],
labels = possible_pairs[[pair_index[[index]]]],
legend = "none"
)
)
Expand All @@ -1241,6 +1252,11 @@ plot.invariance <- function(x, pairs = list(), p_type = c("p", "p_BH"), p_value

}

# Let user know about plot
if(input_pairs && total_pairs > 1){
cat("Use the argument 'pairs = list()' for individual paired results using `c()` inside `list()` (for multiple pairs, use `c()` inside `list()` for each pair).\n")
}

# Return final plots
return(final_plots)

Expand Down

0 comments on commit 0b901d3

Please sign in to comment.