Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding confidence level as a parameter #121

Merged
merged 12 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions R/plotCCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#'
#' @param ellipse.linetype Discrete number specifying the style of ellipses.
#' (default: \code{ellipse.linetype = 1})
#'
#' @param ellipse.level Number between 0 and 1 to adjust confidence level.
#' (default: \code{ellipse.level = 0.95})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't a more descriptive name be "confidence.level"?

#'
#' @param add.vectors TRUE or FALSE, should vectors appear in the plot.
#' (default: \code{add.vectors = TRUE})
Expand Down Expand Up @@ -179,7 +182,7 @@ setGeneric("plotRDA", signature = c("object"),
#' @export
setMethod("plotRDA", signature = c(object = "SingleCellExperiment"),
function(object, dimred,
add.ellipse = TRUE, ellipse.alpha = 0.2, ellipse.linewidth = 0.1, ellipse.linetype = 1,
add.ellipse = TRUE, ellipse.alpha = 0.2, ellipse.linewidth = 0.1, ellipse.linetype = 1, ellipse.level = 0.95,
vec.size = 0.5, vec.color = vec.colour, vec.colour = "black", vec.linetype = 1,
arrow.size = 0.25, label.color = label.colour, label.colour = "black", label.size = 4,
vec.text = TRUE, repel.labels = TRUE, sep.group = "\U2014", repl.underscore = " ",
Expand Down Expand Up @@ -225,6 +228,9 @@ setMethod("plotRDA", signature = c(object = "SingleCellExperiment"),
if ( !is.numeric(ellipse.linewidth) && ellipse.linewidth > 0 ) {
stop("'ellipse.linewidth' must be a positive number.", call. = FALSE)
}
if( ellipse.level < 0 || ellipse.level > 1 ){
stop("'ellipse.level' must be a number between 0 and 1.", call. = FALSE)
}
if ( !is.numeric(vec.size) && vec.size > 0 ) {
stop("'vec.size' must be a positive number.", call. = FALSE)
}
Expand Down Expand Up @@ -256,11 +262,11 @@ setMethod("plotRDA", signature = c(object = "SingleCellExperiment"),
# Create a plot
plot <- .rda_plotter(
plot_data, ellipse.alpha = ellipse.alpha, ellipse.linewidth = ellipse.linewidth,
ellipse.linetype = ellipse.linetype, vec.size = vec.size, vec.color = vec.color,
vec.colour = vec.colour, vec.linetype = vec.linetype, arrow.size = arrow.size,
label.color = label.color, label.colour = label.colour, label.size = label.size,
vec.text = vec.text, add.ellipse = add.ellipse, repel.labels = repel.labels,
parse.labels = parse.labels, ...
ellipse.linetype = ellipse.linetype, ellipse.level = ellipse.level, vec.size = vec.size,
vec.color = vec.color, vec.colour = vec.colour, vec.linetype = vec.linetype,
arrow.size = arrow.size, label.color = label.color, label.colour = label.colour,
label.size = label.size, vec.text = vec.text, add.ellipse = add.ellipse,
repel.labels = repel.labels, parse.labels = parse.labels, ...
)
return(plot)
}
Expand Down Expand Up @@ -493,7 +499,7 @@ setMethod("plotRDA", signature = c(object = "matrix"),
# Plot based on the data
#' @importFrom ggrepel geom_text_repel geom_label_repel
.rda_plotter <- function(
plot_data, ellipse.alpha = 0.2, ellipse.linewidth = 0.1, ellipse.linetype = 1,
plot_data, ellipse.alpha = 0.2, ellipse.linewidth = 0.1, ellipse.linetype = 1, ellipse.level = 0.95,
vec.size = 0.5, vec.color = vec.colour, vec.colour = "black",
vec.linetype = 1, arrow.size = 0.25, min.segment.length = 5,
label.color = label.colour, label.colour = "black", label.size = 4,
Expand All @@ -516,12 +522,12 @@ setMethod("plotRDA", signature = c(object = "matrix"),
aes(x = .data[[xvar]], y = .data[[yvar]],
color = .data[[colour_var]], fill = after_scale(color)),
geom = "polygon", alpha = ellipse.alpha,
linewidth = ellipse.linewidth, linetype = ellipse.linetype)
linewidth = ellipse.linewidth, linetype = ellipse.linetype, level = ellipse.level)
} else if ( add.ellipse %in% c("color", "colour") ){
plot <- plot +
stat_ellipse(data = data,
aes(x = .data[[xvar]], y = .data[[yvar]], color = .data[[colour_var]]),
geom = "polygon", alpha = 0, linetype = ellipse.linetype)
geom = "polygon", alpha = 0, linetype = ellipse.linetype, level = ellipse.level)
}

}
Expand Down
4 changes: 4 additions & 0 deletions man/plotCCA.Rd

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

Loading