Skip to content

Commit

Permalink
Updated legend glyphs for bar plots.
Browse files Browse the repository at this point in the history
  • Loading branch information
enblacar committed Jan 13, 2025
1 parent fb35eb4 commit c1a64a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The reason of these modification is to allow for a much clearer and concise outp
- Added `legend.ncol`, `legend.nrow` and `legend.byrow` parameters to control legend behavior.
- Fixed a bug in which `map_signif_levels` would only accept a logical and not custom mappings.
- When `map_signif_levels` is used, the mapping now appears as a plot legend for clarity.
- Added black borders to the legend glyphs when using `use_silhouette = FALSE`.

## do_ColorPalette()
- Changed "Wheel" to "Color wheel" when plotting the output without additional parameters.
Expand Down
15 changes: 14 additions & 1 deletion R/do_BoxPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ do_BoxPlot <- function(sample,
sample <- out[["sample"]]
group.by <- out[["group.by"]]

# Custom function to draw black border in legend.
# Define the custom draw_key function
draw_key_square_black_border <- function(data,
params,
size) {
grid::rectGrob(width = grid::unit(1, "npc"), # Full size of the key (square)
height = grid::unit(1, "npc"),
gp = grid::gpar(col = "black", # Black border
fill = ggplot2::alpha(data$fill, data$alpha), # Fill with specified color and alpha
lwd = 1) # Border line width
)
}

if (is.null(colors.use)){
if (is.null(split.by)){
colors.use <- generate_color_scale(names_use = if (is.factor(sample@meta.data[, group.by])) {
Expand Down Expand Up @@ -267,7 +280,7 @@ do_BoxPlot <- function(sample,
width = boxplot.width,
lwd = boxplot.linewidth,
fatten = 1,
key_glyph = "rect",
key_glyph = draw_key_square_black_border,
na.rm = TRUE) +
ggplot2::guides(fill = ggplot2::guide_legend(title = legend.title,
title.position = legend.title.position,
Expand Down

0 comments on commit c1a64a1

Please sign in to comment.