Skip to content

sjos_levels ordering is inverted relative to the afsetools vector it documents as ported by value #754

Description

@eduaguilera

What is wrong

whep::sjos_levels is documented as ported by value from
afsetools::load_vectors(), but its ordering is reversed relative to the
source.

afsetools wraps the vector in rev(), so its realised element 1 is
"Exceedance Over":

# afsetools/R/load_vectors.R:684
assign("SJOS_levels", rev(c("Within_boundary Under", "Within_boundary Adequate",
  "Within_boundary Over", "Exceedance Under", "Exceedance Adequate",
  "Exceedance Over")), envir = env)

whep assigns order = 1L to "Within_boundary Under":

# data-raw/sjos_n_coefficients.R:95-116
"Within_boundary Under",    1L, "lightseagreen",
...
"Exceedance Over",          6L, "indianred3"

The colours are ported correctly — all six match SJOS_colours exactly. Only
the order differs.

Consequences

None for classification values: classify_sjos_n() builds a factor over
sjos_levels$level, and membership is unaffected. The effect is on
presentation — stacking order and legend order in any figure meant to reproduce
Global's — which is exactly where a silent inversion is hardest to notice.

Also not carried

Nourish_colours_tot (load_vectors.R:687) and Nourish_levels_tot
(:689), the "Total" variants. nourish_levels itself is correct: whep's
Over / Adequate / Under matches afsetools Nour_levels at :683.

Fix

Either reverse order to match the source, or keep whep's ordering and change
the @source note at R/datasets_sjos_n.R:109-116 so it stops implying the
ordering was inherited. The second is probably better — ascending from
"Within_boundary Under" is the more natural reading — but it should be a stated
choice rather than an accident.

Verified by reading both files; no data or network needed.

Metadata

Metadata

Assignees

Labels

area:nitrogenNitrogen balance & manure allocationbugSomething isn't workingmechanicalNo methodological decision; objectively correct. Reviewable on tests/CI, low-review to merge.no-data-neededFixable and verifiable with no pins, rasters or network; package data onlypriority:lowThere are other more important things

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions