From a4cf69166389d01d30e6a83dc8f8c5dff49d252b Mon Sep 17 00:00:00 2001 From: David Barnett Date: Fri, 25 Jun 2021 12:52:45 +0200 Subject: [PATCH] ord_explore barplot legend fix due to ggplot2 3.3.4 bug https://github.com/tidyverse/ggplot2/issues/4511 --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ R/comp_barplot.R | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8ab68bc0..6bc7af74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: microViz Title: Microbiome Data Analysis and Visualization -Version: 0.7.8 +Version: 0.7.8.9000 Authors@R: person(given = "David", family = "Barnett", diff --git a/NEWS.md b/NEWS.md index 5b42f4ce..9aee4ed8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# microViz (development version) + +- fix (hopefully temporary) for incorrect barplot legend in ord_explore caused by bug introduced by ggplot2 version 3.3.4 noted at https://github.com/tidyverse/ggplot2/issues/4511 + # microViz 0.7.8 - `ord_plot` gains `vec_*` helper functions for generating lists for styling taxa and constraint vectors/arrows (`vec_constraint`, `vec_tax_all` and `vec_tax_sel`) diff --git a/R/comp_barplot.R b/R/comp_barplot.R index ab1a6581..19445a56 100644 --- a/R/comp_barplot.R +++ b/R/comp_barplot.R @@ -347,8 +347,13 @@ comp_barplot <- function(ps, labels = LABELLER ) + ggplot2::scale_fill_manual( - values = palette, - labels = taxon_renamer, + values = palette, labels = taxon_renamer, + # limits = force is a fix (hopefully temporary) for new ggplot2 behaviour + # all named values appear in legend even if they don't exist in the data + # this is a known bug introduced in ggplot2 3.3.4 + # this only matters if named values given for palette, e.g. in ord_explore + # see https://github.com/tidyverse/ggplot2/issues/4511#issuecomment-866185530 + limits = force, guide = ggplot2::guide_legend(title = tax_level, reverse = TRUE) )