Skip to content

drop = TRUE in scale_*_manual no longer drops unused factors (as of v3.3.4) #4595

Closed
@andrewbaxter439

Description

@andrewbaxter439

As of updates 3.3.4 and 3.3.5 the argument to drop unused factor levels seems to have stopped working:

library(tidyverse)

tribble(~group, ~val,
        "a", 5,
        "b", 6,
        "c", 7) %>% 
  ggplot(aes(group, val, fill = group)) +
  geom_col() +
  scale_fill_manual(values = c(
    "a" = "lightblue",
    "b" = "lightgreen",
    "c" = "maroon",
    "d" = "grey"
  ),
  drop = TRUE)

Created on 2021-08-25 by the reprex package (v2.0.0)

Session info
sessionInfo()
#> R version 4.1.0 (2021-05-18)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19041)
#> 
#> Matrix products: default
#> 
#> locale:
#> [1] LC_COLLATE=English_United Kingdom.1252 
#> [2] LC_CTYPE=English_United Kingdom.1252   
#> [3] LC_MONETARY=English_United Kingdom.1252
#> [4] LC_NUMERIC=C                           
#> [5] LC_TIME=English_United Kingdom.1252    
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.5     purrr_0.3.4    
#> [5] readr_1.4.0     tidyr_1.1.3     tibble_3.1.1    ggplot2_3.3.5  
#> [9] tidyverse_1.3.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.1.0  xfun_0.22         haven_2.4.0       colorspace_2.0-0 
#>  [5] vctrs_0.3.7       generics_0.1.0    htmltools_0.5.1.1 yaml_2.2.1       
#>  [9] utf8_1.2.1        rlang_0.4.10      pillar_1.6.0      glue_1.4.2       
#> [13] withr_2.4.2       DBI_1.1.1         dbplyr_2.1.1      modelr_0.1.8     
#> [17] readxl_1.3.1      lifecycle_1.0.0   munsell_0.5.0     gtable_0.3.0     
#> [21] cellranger_1.1.0  rvest_1.0.0       evaluate_0.14     labeling_0.4.2   
#> [25] knitr_1.32        ps_1.6.0          curl_4.3          fansi_0.4.2      
#> [29] highr_0.9         broom_0.7.6       Rcpp_1.0.6        backports_1.2.1  
#> [33] scales_1.1.1      jsonlite_1.7.2    mime_0.10         farver_2.1.0     
#> [37] fs_1.5.0          hms_1.0.0         digest_0.6.27     stringi_1.5.3    
#> [41] grid_4.1.0        cli_2.4.0         tools_4.1.0       magrittr_2.0.1   
#> [45] crayon_1.4.1      pkgconfig_2.0.3   ellipsis_0.3.1    xml2_1.3.2       
#> [49] reprex_2.0.0      lubridate_1.7.10  assertthat_0.2.1  rmarkdown_2.7    
#> [53] httr_1.4.2        rstudioapi_0.13   R6_2.5.0          compiler_4.1.0

By contrast, the code running on v3.3.3 produces the desired result:

Created on 2021-08-25 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions