Skip to content

Commit

Permalink
More options in box_plot and chord_diagram_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
iflint1 committed Mar 8, 2024
1 parent f3678a9 commit d06d377
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
21 changes: 18 additions & 3 deletions R/box_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ convert_names <- function(x,
#' Only works when given a single fit.
#' Should be a named vector/list, with the names corresponding to types, and the value equal to the class name.
#' @param involving Optional vector/list of types. Only coefficients involving these types will be plotted.
#' @param how If the `involving` argument is supplied, should it involve *only* those types, or at least *one* of those types (which is relevant if inter-type interactions are involved).
#' @export
#' @keywords internal
#' @md
Expand All @@ -164,7 +165,8 @@ make_summary_df <- function(fits,
full_names,
compute_confidence_intervals,
classes,
involving) {
involving,
how) {
# Take care of the classes argument
if(!is.null(classes)) {
classes <- as.list(classes)
Expand Down Expand Up @@ -225,8 +227,15 @@ make_summary_df <- function(fits,
types
}

# Should other types be considered?
other_types_subset <- if(how == "only") {
types_subset
} else {
types
}

if(identification != "beta") { # Create dataframe of two columns with all possible pairs of types
d <- as.data.frame(expand.grid(from = types, to = types_subset, stringsAsFactors = FALSE))
d <- as.data.frame(expand.grid(from = other_types_subset, to = types_subset, stringsAsFactors = FALSE))
d <- d[!duplicated(t(apply(d, 1, sort))), ]

if(which == "within") { # in this case, remove columns that are the same, so shows only between interactions
Expand Down Expand Up @@ -365,6 +374,7 @@ make_summary_df <- function(fits,
#' Only works when given a single fit.
#' Should be a named vector/list, with the names corresponding to types, and the value equal to the class name.
#' @param involving Optional vector/list of types. Only coefficients involving these types will be plotted.
#' @param how If the `involving` argument is supplied, should it involve *only* those types, or at least *one* of those types (which is relevant if inter-type interactions are involved).
#' @param title Plot title.
#' @param colours Optional vector of colours to represent the different fits/classes.
#' @param highlight_zero Highlight the zero value with a red line?
Expand Down Expand Up @@ -403,13 +413,17 @@ box_plot <- function(...,
compute_confidence_intervals = TRUE,
classes = NULL,
involving = NULL,
how = c("only", "one"),
title,
colours = c("black", "#5BBCD6", "#F2AD00", "#00A08A", "#FF0000"),
highlight_zero = TRUE,
text_size = 16,
base_size = 20,
xmin,
xmax) {
# Interpret the how argument
how <- match.arg(how)

# TODO: Avoid NULL default arguments for args forwarded to internal function, just set those to NULL in there
# TODO: Is there a clean way to copy the documentation between functions when they have the same arguments? See box_plot and chord_diagram, all the gibbsm rgibbs functions, etc.
# Interpret the which argument
Expand All @@ -425,7 +439,8 @@ box_plot <- function(...,
full_names = full_names,
compute_confidence_intervals = compute_confidence_intervals,
classes = classes,
involving = involving)
involving = involving,
how = how)

# Remove NAs
df <- df[rowSums(is.na(df)) == 0, ]
Expand Down
8 changes: 7 additions & 1 deletion R/chord_diagram.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#' @param classes If this parameter is supplied, then colours are used to distinguish classes.
#' Should be a named vector/list, with the names corresponding to types, and the value equal to the class name.
#' @param involving Optional vector/list of types. Only coefficients involving these types will be plotted.
#' @param how If the `involving` argument is supplied, should it involve *only* those types, or at least *one* of those types (which is relevant if inter-type interactions are involved).
#' @param include_self Include self-interactions?
#' @param show_legend Show legend(s)?
#' @param cex Cex.
Expand Down Expand Up @@ -54,6 +55,7 @@ chord_diagram_plot <- function(fit,
compute_confidence_intervals = TRUE,
classes = NULL,
involving = NULL,
how = c("only", "one"),
include_self = TRUE,
show_legend = TRUE,
cex = 1,
Expand All @@ -68,6 +70,9 @@ chord_diagram_plot <- function(fit,
big_gap = 5,
repulsion_attraction_colours = c("blue", "red"),
classes_colours) {
# Interpret the how argument
how <- match.arg(how)

# Take care of repulsion_attraction_colours argument
if(!is.character(repulsion_attraction_colours) | length(repulsion_attraction_colours) != 2) {
stop("repulsion_attraction_colours should be a vector containing two strings, the first one a colour to represent negative interactions, the second one representing positive interactions.")
Expand All @@ -88,7 +93,8 @@ chord_diagram_plot <- function(fit,
full_names = full_names,
compute_confidence_intervals = compute_confidence_intervals,
classes = classes,
involving = involving)
involving = involving,
how = how)

# Remove NAs
chord_diagram <- chord_diagram[rowSums(is.na(chord_diagram)) == 0, ]
Expand Down
3 changes: 3 additions & 0 deletions man/box_plot.Rd

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

3 changes: 3 additions & 0 deletions man/chord_diagram_plot.Rd

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

5 changes: 4 additions & 1 deletion man/make_summary_df.Rd

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

0 comments on commit d06d377

Please sign in to comment.