FRBCesab / funbiogeo

:package: R package to help with analyses in functional biogeography
https://frbcesab.github.io/funbiogeo/
GNU General Public License v2.0
10 stars 1 forks source link

fb_plot_species_traits_completeness() only shows red when trait matrix is complete #111

Closed Rekyt closed 6 months ago

Rekyt commented 6 months ago

Bug description

See issue title

Reproducible example

library("dplyr")
#> Warning: le package 'dplyr' a été compilé avec la version R 4.3.2
#> 
#> Attachement du package : 'dplyr'
#> Les objets suivants sont masqués depuis 'package:stats':
#> 
#>     filter, lag
#> Les objets suivants sont masqués depuis 'package:base':
#> 
#>     intersect, setdiff, setequal, union

data("aravo", package = "ade4")

# All red should be all blue
aravo$traits %>%
  tibble::rownames_to_column("species") %>%
  funbiogeo::fb_plot_species_traits_completeness()

Created on 2024-04-09 with reprex v2.1.0

The problem comes from the fact that the colors are defined here:

https://github.com/FRBCesab/funbiogeo/blob/faaad76e42ba2da125978eea9ddb87c436b8eff2/R/fb_plot_species_traits_completeness.R#L233-L236

If the entirety of "has_trait" column is TRUE, then only the first color of ColorBrewer Set1 is used -> the red

The fix is quite easy: change from using scale_fill_brewer() to scale_fill_manual() with the colors set up as the two first colors of Color Brewer.