hugomflavio / actel

Standardised analysis of acoustic telemetry data from fish moving through receiver arrays
https://hugomflavio.github.io/actel-website
26 stars 6 forks source link

array factor ordering #65

Closed sebdalgarno closed 3 years ago

sebdalgarno commented 3 years ago

Hi again @hugomflavio ! I'm trying to reorder my Array values (as factors). I've browsed the vignettes but unable to find an answer there - apologies if this is documented somewhere.

I have a set of array names (A1, A2, A3, A4, etc.). I can set the factor order (based on river kilometer rkm) with forcats like:

mutate(Array = fct_reorder(Array, rkm, min))

When I run preload() the factors are reset to what it would be if the following was run (i.e. based on order seen in data.frame):

mutate(Array = as.factor(Array))

The order is wrong here (i.e. A4, A2, A3 ...) and the jump checks and visualizations don't work well as a result.

Any suggestion for setting the order of Array?

Thanks!

sebdalgarno commented 3 years ago

OK I see now that this can be done by arranging the order of the data.frame, e.g.

spatial %<>% arrange(rkm)

The factor level order is then set properly. I wonder if it would be possible to preserve factor level order? Obviously not a big priority but just a thought.

hugomflavio commented 3 years ago

Hi again Seb,

This is a conserved mechanism that comes from the older versions of actel, where the only acceptable input were CSV files. There, the easiest way to organise the stations would be to sort them by array in the spatial file. The preload() function follows this logic for consistency. However, you are able to manually provide a specific array order using the dot argument. Specifically, if you want the array order to be the same as the levels of the Array column, you could state dot = paste0(levels(spatial$Array), collapse = "--") in your preload call.

The dot file (which I named 'spatial.txt' for simplicity) tells actel how the arrays are positioned relative to eachother. You can read more about it in this section of the manual.

I hope this helps!

sebdalgarno commented 3 years ago

that's great thanks @hugomflavio !