diff --git a/DESCRIPTION b/DESCRIPTION index a722f627..5483e807 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: fluxible Title: Ecosystem Gas Fluxes Calculations for Closed Loop Chamber Setup -Version: 1.3.6 -Date: 2026-02-05 +Version: 1.3.7 +Date: 2026-03-17 Authors@R: c(person(given = "Joseph", family = "Gaudard", , "joseph.gaudard@pm.me", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6989-7624")), diff --git a/NEWS.md b/NEWS.md index 727580b1..ffdd2bd6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# fluxible 1.3.7 + +* `flux_plot`: argument `arrange_col` allows to customize the order of the facets + # fluxible 1.3.6 * fixed the use of `case_when()` to avoid warnings with `dplyr 1.2.0`. diff --git a/R/flux_fortify.R b/R/flux_fortify.R index 24babf0f..e074bf59 100644 --- a/R/flux_fortify.R +++ b/R/flux_fortify.R @@ -22,7 +22,8 @@ flux_fortify <- function(slopes_df, f_ylim_upper, f_ylim_lower, f_facetid, - y_text_position) { + y_text_position, + arrange_col) { args_ok <- flux_fun_check(list( f_ylim_upper = f_ylim_upper, @@ -44,6 +45,7 @@ flux_fortify <- function(slopes_df, select( {{f_conc}}, {{f_datetime}}, + {{arrange_col}}, all_of(f_facetid), any_of(c( "f_quality_flag", @@ -108,14 +110,19 @@ flux_fortify <- function(slopes_df, nb_fluxid <- n_distinct(slopes_df$f_fluxid) # customize facet ID + slopes_df <- slopes_df |> unite( col = "f_facetid", all_of(f_facetid), - sep = " " + sep = " ", + remove = FALSE ) |> + arrange({{arrange_col}}, {{f_datetime}}) |> mutate( - f_facetid = fct_reorder(f_facetid, {{f_datetime}}) + .by = "f_facetid", + rowid = cur_group_id(), + f_facetid = fct_reorder(f_facetid, .data$rowid) ) # testing if f_facetid is unique, otherwise facet will make a mess diff --git a/R/flux_plot.R b/R/flux_plot.R index 5b5fd1ec..87f6e60a 100644 --- a/R/flux_plot.R +++ b/R/flux_plot.R @@ -40,6 +40,8 @@ #' measurement. Default is `f_fluxid` #' @param longpdf_args arguments for longpdf in the form #' `list(ncol, width (in cm), ratio)` +#' @param arrange_col character vector of columns to use to reorder the facets. +#' If NULL (default), facets are ordered by the datetime of the measurement. #' @return plots of fluxes, with raw concentration data points, fit, slope, #' and color code indicating quality flags and cuts. The plots are organized #' in facets according to flux ID, and a text box display the quality flag and @@ -99,9 +101,12 @@ flux_plot <- function(slopes_df, y_text_position = 500, print_plot = "FALSE", output = "print_only", - ggsave_args = list()) { + ggsave_args = list(), + arrange_col = c()) { # fortify data + + slopes_params <- flux_fortify( slopes_df = slopes_df, f_conc = {{f_conc}}, @@ -109,7 +114,8 @@ flux_plot <- function(slopes_df, f_ylim_upper = f_ylim_upper, f_ylim_lower = f_ylim_lower, f_facetid = f_facetid, - y_text_position = y_text_position + y_text_position = y_text_position, + arrange_col = {{arrange_col}} ) slopes_df <- slopes_params$slopes_df diff --git a/README.Rmd b/README.Rmd index 3fcb54dd..17092d9e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -128,6 +128,10 @@ fluxes_gpp The [`licoread` R package](https://jogaudard.github.io/licoread/index.html), developed in collaboration with [LI-COR](https://www.licor.com/), provides an easy way to import raw files from LI-COR gas analyzers as R objects that can be used directly with the `fluxible` R package. +### `readosense` R package + +The [`readosense` R package](https://jogaudard.github.io/readosense/index.html) provides an easy way to import raw files from [Eosense](https://eosense.com/) multi chamber ecosystem gas flux setups as R objects that can be used directly with the `fluxible` R package. + ## Further developments ### Segmentation tool diff --git a/README.md b/README.md index 9a306a6d..3f43ec25 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,14 @@ collaboration with [LI-COR](https://www.licor.com/), provides an easy way to import raw files from LI-COR gas analyzers as R objects that can be used directly with the `fluxible` R package. +### `readosense` R package + +The [`readosense` R +package](https://jogaudard.github.io/readosense/index.html) provides an +easy way to import raw files from [Eosense](https://eosense.com/) multi +chamber ecosystem gas flux setups as R objects that can be used directly +with the `fluxible` R package. + ## Further developments ### Segmentation tool diff --git a/dev/dev.R b/dev/dev.R index 49683084..f56cb492 100644 --- a/dev/dev.R +++ b/dev/dev.R @@ -27,7 +27,7 @@ devtools::load_all() # autoimport::autoimport() devtools::document() -devtools::test(filter = "flux_calc") +devtools::test(filter = "flux_plot") devtools::test() devtools::run_examples() devtools::check() diff --git a/man/flux_fortify.Rd b/man/flux_fortify.Rd index d2a08408..9fdd25c9 100644 --- a/man/flux_fortify.Rd +++ b/man/flux_fortify.Rd @@ -11,7 +11,8 @@ flux_fortify( f_ylim_upper, f_ylim_lower, f_facetid, - y_text_position + y_text_position, + arrange_col ) } \arguments{ diff --git a/man/flux_plot.Rd b/man/flux_plot.Rd index 89134651..9d0dd71f 100644 --- a/man/flux_plot.Rd +++ b/man/flux_plot.Rd @@ -23,7 +23,8 @@ flux_plot( y_text_position = 500, print_plot = "FALSE", output = "print_only", - ggsave_args = list() + ggsave_args = list(), + arrange_col = c() ) } \arguments{ @@ -78,6 +79,9 @@ but will take time depending on the size of the dataset} \item{ggsave_args}{list of arguments for \link[ggplot2:ggsave]{ggsave} (in case \code{output = "ggsave"})} + +\item{arrange_col}{character vector of columns to use to reorder the facets. +If NULL (default), facets are ordered by the datetime of the measurement.} } \value{ plots of fluxes, with raw concentration data points, fit, slope, diff --git a/tests/testthat/_snaps/flux_plot/facet-ordering.svg b/tests/testthat/_snaps/flux_plot/facet-ordering.svg new file mode 100644 index 00000000..1b127455 --- /dev/null +++ b/tests/testthat/_snaps/flux_plot/facet-ordering.svg @@ -0,0 +1,1774 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ok +R2 = 0.91 +p-value = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ok +R2 = 0.95 +p-value = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ok +R2 = 0.99 +p-value = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +zero +R2 = 0.01 +p-value = 0.283588 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ok +R2 = 1 +p-value = 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +ok +R2 = 0.94 +p-value = 0 + + + + + + + + + + + + +6 f + + + + + + + + + + +5 m + + + + + + + + + + +3 a + + + + + + + + + + +1 b + + + + + + + + + + +2 c + + + + + + + + + + +4 f + + + + + + +29/07 + 00:07 +29/07 + 00:08 +29/07 + 00:09 +29/07 + 00:10 + + + + +29/07 + 00:03 +29/07 + 00:04 +29/07 + 00:05 +29/07 + 00:06 + + + + +28/07 + 23:52 +28/07 + 23:53 +28/07 + 23:54 +28/07 + 23:55 + + + + +28/07 + 23:44 +28/07 + 23:45 +28/07 + 23:46 +28/07 + 23:47 + + + + +28/07 + 23:48 +28/07 + 23:49 +28/07 + 23:50 +28/07 + 23:51 + + + + +29/07 + 00:00 +29/07 + 00:01 +29/07 + 00:02 +29/07 + 00:03 +400 +500 +600 +700 +800 + + + + + +400 +500 +600 +700 +800 + + + + + +400 +500 +600 +700 +800 + + + + + +400 +500 +600 +700 +800 + + + + + +400 +500 +600 +700 +800 + + + + + +400 +500 +600 +700 +800 + + + + + +Datetime +Concentration + +Quality flags + + + + + + +cut +ok +zero + +Fits + + +f_fit_slope +linear model +Fluxes quality assessment + + diff --git a/tests/testthat/test-flux_plot.R b/tests/testthat/test-flux_plot.R index 47b184bb..bca39ebd 100644 --- a/tests/testthat/test-flux_plot.R +++ b/tests/testthat/test-flux_plot.R @@ -515,3 +515,36 @@ test_that("slope crosses fit at tz with quadratic", { ) ) }) + +test_that("facet ordering", { + slopes30lin_flag <- suppressWarnings(flux_fitting( + co2_conc, + conc, + datetime, + fit_type = "linear", + end_cut = 30 + )) |> + flux_quality( + conc + ) |> + mutate( + plotID = f_fluxid, + plotID = case_when( + plotID == 1 ~ "b", + plotID == 2 ~ "c", + plotID == 3 ~ "a", + plotID == 4 ~ "f", + plotID == 5 ~ "m", + plotID == 6 ~ "f" + ) + ) + + plot_object <- flux_plot( + slopes30lin_flag, + conc, + datetime, + f_facetid = c("f_fluxid", "plotID"), + arrange_col = plotID + ) + vdiffr::expect_doppelganger("facet ordering", plot_object) +}) diff --git a/vignettes/data-prep.Rmd b/vignettes/data-prep.Rmd index 469cc96b..c9432ed3 100644 --- a/vignettes/data-prep.Rmd +++ b/vignettes/data-prep.Rmd @@ -23,6 +23,7 @@ The `readr::read_delim` [@readr2024] function works perfectly in most cases, giv We provide here examples on how to use `read_delim` to prepare your raw data files for the `fluxible` R package. For users of Li-COR instruments, the [`licoread` R package](https://jogaudard.github.io/licoread/index.html), developed in collaboration with Li-COR, is designed to read 82z and 81x files and import them as `fluxible`-friendly objets. +Eosense ecosystem gas flux chambers users can also use the [`readosense` R package](https://jogaudard.github.io/readosense/) to read their raw files and import them as `fluxible`-friendly objects. ## Checklists for inputs