torv72 / torv-reports-v4

1 stars 0 forks source link

Add option to adjust minerals shown in trend plots #13

Closed z3tt closed 1 week ago

z3tt commented 5 months ago

It would be great to be able to decide which minerals are shown in the trend facet.

This may result in some bigger changes of the current workflow. Currently, the facet is built from single plots using {patchwork}, mainly to be able to include the "how to read" plot. However, as this legend is always the same and is repeated multiple times across the report, we will change this logic (see #14 ).

This means that we are likely moving to a facet_wrap() approach which hopefully simplifies a few things and should allow for a clever logic in laying out an unknown number of panels.

Things to consider:

z3tt commented 3 months ago

We are sticking to the patchwork approach (see #14).

The workflow should allow to add more measurement names. However, no logic for removing specific names needs to be implemented!

→ I thought of a simple .additional_minerals argument (or whatever name you prefer) which then is used to determine the final list of measurement names to be used for the trendline plot.

Note to myself: We also need some logic for determining the height of the overall small multiples.

torv72 commented 3 months ago

I think that would work just fine. .additional_minerals is a fine argument name.

z3tt commented 1 week ago

You can now use the .measurements_add argument in generate_report() to add additional measurement names. Those need to be exactly named as in the database. Those are added to the end of the list (and thus at the end of the trendline charts).

The .measurement_default argument is only needed in case you want to change the complete list. It is set to the common list of 11 measurement name. It can be overwritten (see example further below) but you don't have to specify it to leave it as it is.

.measurements_default = c(
  "pH",
  "Organic Matter (%)",
  "Total Nitrogen (ppm)",
  "Potassium (ppm)",
  "Phosphorus (ppm)", 
  "Calcium (ppm)",
  "Magnesium (ppm)",
  "Sodium (ppm)",
  "Sulfur (ppm)",
  "Iron (ppm)",
  "Manganese (ppm)",
  "Micronutrients"
)

If you want to add e.g. Aluminium, you'd specify .measurements_add = "Aluminum (lbs/ac in)" (or a vector of names when defining multiple names to be added, .e.g. c("Aluminum (lbs/ac in)", "C/N Ratio As-Is (ppm)")).

In case you want to e.g. remove pH, Sulfur, and Micronutrients, you would overwrite the defaults like this:

.measurements_default = c(
  "Organic Matter (%)",
  "Total Nitrogen (ppm)",
  "Potassium (ppm)",
  "Phosphorus (ppm)", 
  "Calcium (ppm)",
  "Magnesium (ppm)",
  "Sodium (ppm)",
  "Iron (ppm)",
  "Manganese (ppm)"
)

You could also use the .measurements_default argument to add measurements but that would require copy-pasting the full list (thus, .measurements_add is meant to act as a shortcut). It's also helpful if you want to reorder the default names or place the additional measurement somewhere else than at the end:

.measurements_default = c(
  "pH",
  "Organic Matter (%)",
  "Aluminum (lbs/ac in)", ## place as the third plot
  "Total Nitrogen (ppm)",
  "Potassium (ppm)",
  "Phosphorus (ppm)", 
  "Calcium (ppm)",
  "Magnesium (ppm)",
  "Sodium (ppm)",
  "Sulfur (ppm)",
  "Iron (ppm)",
  "Manganese (ppm)",
  "Micronutrients"
)
torv72 commented 1 week ago

Just tested it out. Looks like it worked great! Thank you.

On Oct 21, 2024, at 11:34 AM, Cédric Scherer @.***> wrote:

You can now use the .measurements_add argument in generate_report() to add additional measurement names. Those need to be exactly named as in the database.

The .measurement_default argument is only needed in case you want to change the complete list. It is set to the common list of 11 measurement names but can be overwritten.

.measurements_default = c( "pH", "Organic Matter (%)", "Total Nitrogen (ppm)", "Potassium (ppm)", "Phosphorus (ppm)", "Calcium (ppm)", "Magnesium (ppm)", "Sodium (ppm)", "Sulfur (ppm)", "Iron (ppm)", "Manganese (ppm)", "Micronutrients" ) If you want to add e.g. Aluminium, you'd specify .measurements_add = "Aluminum (lbs/ac in)" (or a vector of names when defining multiple names to be added, .e.g. c("Aluminum (lbs/ac in)", "C/N Ratio As-Is (ppm)")). In case you want to e.g. remove pH, Sulfur, and "Micronutrients, you would overwrite the defaults like this:

.measurements_default = c( "Organic Matter (%)", "Total Nitrogen (ppm)", "Potassium (ppm)", "Phosphorus (ppm)", "Calcium (ppm)", "Magnesium (ppm)", "Sodium (ppm)", "Iron (ppm)", "Manganese (ppm)" ) You could also use the .measurements_default argument to add measurements but that would require compy-pasting the full list (thus, .measurements_add is meant to act as a shortcut). It's also helpful if you want to reorder the default names pr place the additional measurement somewhere else than at the end:

.measurements_default = c( "pH", "Organic Matter (%)", "Aluminum (lbs/ac in)", ## place as third plot "Total Nitrogen (ppm)", "Potassium (ppm)", "Phosphorus (ppm)", "Calcium (ppm)", "Magnesium (ppm)", "Sodium (ppm)", "Sulfur (ppm)", "Iron (ppm)", "Manganese (ppm)", "Micronutrients" ) — Reply to this email directly, view it on GitHub https://github.com/torv72/torv-reports-v4/issues/13#issuecomment-2427327722, or unsubscribe https://github.com/notifications/unsubscribe-auth/AVVJE26NW6TQUH55GDPB3J3Z4U3LBAVCNFSM6AAAAABIFHSDFSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRXGMZDONZSGI. You are receiving this because you commented.

z3tt commented 1 week ago

A note on the behaviou:

The height of the figure is based on the number of plots (i.e. the number of rows). It's an approximation so it might not be the exact height when changing the number of resulting rows but look fine for all cases.

If you are adding a lot of additional measurements (I assume more than 4) then you likely run into issues when plotting the figure in the PDF report (because of the page limitations).