Skip to content

Commit

Permalink
feat: support named palcolor and keep the order (pwwang/scplotter#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Nov 21, 2024
1 parent 38fc906 commit 9b4c9c3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Imports:
cowplot,
zoo
Suggests:
testthat,
ComplexHeatmap,
clustree,
gglogger,
Expand Down
6 changes: 5 additions & 1 deletion R/theming.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,17 @@ palette_this <- function(
n_x <- nlevels(x)
if (isTRUE(attr(palcolor, "type") == "continuous")) {
color <- colorRampPalette(palcolor)(n_x)
names(color) <- levels(x)
} else if (!is.null(names(palcolor))) {
color <- palcolor[intersect(names(palcolor), levels(x))]
} else {
color <- ifelse(rep(n_x, n_x) <= pal_n,
palcolor[1:n_x],
colorRampPalette(palcolor)(n_x)
)
names(color) <- levels(x)
}
names(color) <- levels(x)

if (any(is.na(x))) {
color <- c(color, setNames(NA_color, "NA"))
}
Expand Down
2 changes: 1 addition & 1 deletion man/LinePlot.Rd

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

2 changes: 1 addition & 1 deletion man/ScatterPlot.Rd

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

0 comments on commit 9b4c9c3

Please sign in to comment.