Skip to content

Commit

Permalink
Added the use of multiple legends in do_FeaturePlot, and enhanced sta…
Browse files Browse the repository at this point in the history
…rtup message.
  • Loading branch information
enblacar committed Jul 15, 2024
1 parent 03be07d commit e9eace2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SCpbur v2.0.3 (In Development)

## General
- Enhanced startup message for clarity. Not it guides the user to run `SCpubr::package_report(extended = TRUE)` to get an overview of the missing dependencies.

## Added functions
- `do_WafflePlot()`: This function displays proportions as a pictogram grid of 10x10 tiles. It helps to visually see at a glance the proportions of your data. This fails to correctly convey decimal proportions and completely ignores heavily under-represented classes in your dataset.
- `do_RankedExpressionPlot()` to plot expression values as a heatmap along a diffusion component.
Expand Down Expand Up @@ -57,6 +60,7 @@ The reason of these modification is to allow for a much clearer and concise outp

## do_FeaturePlot()
- Fixed a bug in which legend titles would not show up as intended.
- Enabled the use of several legend titles when multiple features are provided. The number of legend titles and features have to be equal.

## do_LigandReceptorPlot()
- Added a new parameter `top_interactions_by_group` which when set to `TRUE` will report for each pair of `source` and `target`, as many interactions as stated in `top_interactions`.
Expand Down
26 changes: 15 additions & 11 deletions R/do_FeaturePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,16 @@ do_FeaturePlot <- function(sample,
group.by.colors.use <- generate_color_scale(names.use)
}
}


# Check that the legend title match the length of features.
if (!is.null(legend.title)){
assertthat::assert_that(length(legend.title) == length(features),
msg = paste0(add_cross(), crayon_body("Please provide as many different "),
crayon_key("legend titles"),
crayon_body(" as number of "),
crayon_key("features"),
crayon_body(" queried.")))
}


check_parameters(parameter = font.type, parameter_name = "font.type")
Expand Down Expand Up @@ -1016,7 +1025,11 @@ do_FeaturePlot <- function(sample,
counter <- 0
for (feature in features){
counter <- counter + 1
legend.title.use <- ifelse(is.null(legend.title), feature, legend.title)
if (is.null(legend.title)){
legend.title.use <- feature
} else {
legend.title.use <- legend.title[counter]
}
p[[counter]] <- modify_continuous_legend(p = p[[counter]],
legend.title = legend.title.use,
legend.aes = "color",
Expand Down Expand Up @@ -1126,15 +1139,6 @@ do_FeaturePlot <- function(sample,

}

# Add legend titles.
if (is.null(split.by) & is.null(legend.title)){
counter <- 0
for (feature in features){
counter <- counter + 1
p[[counter]]$guides$colour$title <- feature
}
}

# Return the plot.
return(p)
}
19 changes: 11 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,13 @@ package_report <- function(startup = FALSE,
url = "https://github.com/enblacar/SCpubr/releases")),
crayon_body(" page."))

functions_tip3 <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" Check the package requirements function-wise with: "),
cli::style_italic(crayon_key('SCpubr:::return_dependencies()')))
}
tip_rule <- cli::rule(left = "Tips!", width = nchar("Tips!") + 6)


ins_message <- paste0(cli::style_bold(cli::col_blue("!")),
crayon_body(" Check missing dependencies with: "),
cli::style_italic(crayon_key('SCpubr::package_report(extended = TRUE)')))

tip_message <- paste0(cli::style_bold(cli::col_cyan(cli::symbol$info)),
crayon_body(" To remove the white and black end from continuous palettes, use: "),
cli::style_italic(crayon_key('options("SCpubr.ColorPaletteEnds" = FALSE)')))
Expand Down Expand Up @@ -765,9 +766,9 @@ package_report <- function(startup = FALSE,
functions_check, "\n", "\n",
paste(print.list.functions, collapse = "\n"), "\n", "\n",
functions_tip1, "\n",
functions_tip2, "\n",
functions_tip3, "\n", "\n", "\n", "\n",
functions_tip2, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
ins_message, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
Expand All @@ -780,6 +781,7 @@ package_report <- function(startup = FALSE,
updates, "\n", "\n",
plotting, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
ins_message, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
Expand All @@ -797,9 +799,9 @@ package_report <- function(startup = FALSE,
functions_check, "\n", "\n",
paste(print.list.functions, collapse = "\n"), "\n", "\n",
functions_tip1, "\n",
functions_tip2, "\n",
functions_tip3, "\n", "\n", "\n", "\n",
functions_tip2, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
ins_message, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
Expand All @@ -812,6 +814,7 @@ package_report <- function(startup = FALSE,
updates, "\n", "\n",
plotting, "\n", "\n", "\n", "\n",
tip_rule, "\n", "\n",
ins_message, "\n", "\n",
tip_message, "\n", "\n",
disable_message, "\n", "\n",
end_rule)
Expand Down

0 comments on commit e9eace2

Please sign in to comment.