Skip to content

Commit

Permalink
support indices
Browse files Browse the repository at this point in the history
Signed-off-by: Daena Rys <[email protected]>
  • Loading branch information
Daenarys8 committed Nov 7, 2024
1 parent 6154e28 commit c87ec55
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions R/plotScree.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ setMethod("plotScree", signature = c(x = "SingleCellExperiment"),
}
eig <- attributes(reduced_dim)[ind][[1]]
# Call the vector method
result <- plotScree(as.numeric(eig), names(eig), cumulative = cumulative, ...)
result <- plotScree(as.numeric(eig), cumulative = cumulative, ...)
return(result)
}
)
Expand All @@ -109,15 +109,19 @@ setMethod("plotScree", signature = c(x = "vector"),
warning("NA values found in eigenvalues;
they will be omitted from the plot.")
}
plot_data <- .prepare_data(x, cumulative)
plot_data <- .prepare_data(x, cumulative, ...)
# plot vector
result <- .scree_plotter(plot_data, cumulative = cumulative, ...)
result <- .scree_plotter(plot_data, cumulative, ...)
return(result)
}
)
.prepare_data <- function(x, cumulative = FALSE) {
.prepare_data <- function(x, cumulative = FALSE, indices = NULL, ...) {
# drop NA values in eigenvalues
x <- x[!is.na(x)]
# Subset eigenvalues based on indices (if provided)
if (!is.null(indices)) {
x <- x[indices]
}
df <- data.frame(
component = if (!is.null(names(x))) names(x) else seq_along(x),
Eigenvalue = x
Expand All @@ -128,12 +132,13 @@ setMethod("plotScree", signature = c(x = "vector"),
}
return(df)
}
.scree_plotter <- function(df, show.barplot = TRUE,
.scree_plotter <- function(df, cumulative = FALSE,
show.barplot = TRUE,
show.points = TRUE,
show.line = TRUE, show.labels = FALSE,
cumulative = FALSE, ...) {
show.line = TRUE,
show.labels = FALSE, ...) {
# Create base plot
p <- ggplot(df, aes(x = Component, y = if (cumulative)
p <- ggplot(df, aes(x = component, y = if (cumulative)
CumulativeProportion else Eigenvalue))
# Add layers based on user preferences
if (show.barplot) {
Expand Down

0 comments on commit c87ec55

Please sign in to comment.