inbo / n2khab

R package with preprocessing functions and standard reference data for Flemish Natura 2000 (N2K) habitat (HAB) analyses
https://inbo.github.io/n2khab
GNU General Public License v3.0
2 stars 1 forks source link

map/legend color mismatch in vignette example map #187

Open falkmielke opened 4 weeks ago

falkmielke commented 4 weeks ago

Dear all,

I encountered a very minor issue when working through the n2khab::v022_example vignette. The following code block (slightly modified from the vignette: using explan=TRUE and native pipes) produces a soil map of the Zwin:

sm_simple |>
    filter(bsm_region == "Zwin") |>
    mutate(bsm_mo_tex = as.character(bsm_mo_tex),
           bsm_mo_tex_explan = as.character(bsm_mo_tex_explan)) |>
    mapview(
        zcol = "bsm_mo_tex_explan",
        alpha.region = 0.2,
        map.types = c("OpenStreetMap", "OpenTopoMap")
    )

However, the colors on the map do not match the legend. The firsts categoy, "klei", gets a gray tint instead of dark blue. Gray seems to be reserved for NA, which we probably don't have in the Zwin.

I would expect R | sf to use the fillColor attribute consistently for map and legend, which is correctly set to dark blue #4B0055 for klei (correct on legend, but not displayed on the map).

Screenshot_2024-08-21_13-48-13

I suspect an issue with R factors in sf, or some hiccup with the fillColor attribute (spelling?). Probably this is upstream but can be controlled with some extra args.

Note that this is least priority; I am just fond of writing issues. I am currently just beginning to read into the package, and will happily get back here to solve this myself once I understand more.

Cheers,

Falk

edit: sys info for reference

> sessionInfo()
R version 4.4.1 (2024-06-14)
Platform: x86_64-pc-linux-gnu
Running under: Manjaro Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.12.0 
LAPACK: /usr/lib/liblapack.so.3.12.0

other attached packages:
 [1] units_0.8-5     mapview_2.11.2  sf_1.0-16       lubridate_1.9.3
 [5] forcats_1.0.0   stringr_1.5.1   dplyr_1.1.4     purrr_1.0.2    
 [9] readr_2.1.5     tidyr_1.3.1     tibble_3.2.1    ggplot2_3.5.1  
[13] tidyverse_2.0.0 knitr_1.48      n2khab_0.10.1  
florisvdh commented 4 weeks ago

Thanks! I think it's because of the alpha.region = 0.2 setting, which sets transparency. Two things to note: