From ea6842af480274528ebcd9aa74022f688310ecdf Mon Sep 17 00:00:00 2001 From: Timon Date: Wed, 25 Jun 2025 10:39:26 +0200 Subject: [PATCH] minor visualistion chagnes --- r_app/CI_report_dashboard_planet.Rmd | 35 +++++++++++++++++----------- r_app/report_utils.R | 8 +++---- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/r_app/CI_report_dashboard_planet.Rmd b/r_app/CI_report_dashboard_planet.Rmd index 86f3aef..1f020ad 100644 --- a/r_app/CI_report_dashboard_planet.Rmd +++ b/r_app/CI_report_dashboard_planet.Rmd @@ -357,7 +357,8 @@ CI values typically range from 0 (bare soil or severely stressed vegetation) to Use these insights to identify areas that may need irrigation, fertilization, or other interventions, and to track the effectiveness of your management practices over time. -\pagebreak +\newpage + # RGB Satellite Image - Current Week (if available) ```{r render_rgb_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} # Check if RGB bands are available and create RGB map @@ -440,6 +441,7 @@ tryCatch({ ``` \newpage + # Chlorophyll Index (CI) Overview Map - Current Week ```{r render_ci_overview_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} # Create overview chlorophyll index map @@ -468,7 +470,6 @@ tryCatch({ # Base shape ``` \newpage -\pagebreak # Weekly Chlorophyll Index Difference Map ```{r render_ci_difference_map, echo=FALSE, fig.height=7, fig.width=10, message=FALSE, warning=FALSE} @@ -498,9 +499,8 @@ tryCatch({ # Base shape ``` \newpage -\pagebreak -```{r generate_field_visualizations, eval=TRUE, fig.height=4.5, fig.width=12, message=FALSE,echo=FALSE, warning=FALSE, include=TRUE, results='asis'} +```{r generate_field_visualizations, eval=TRUE, fig.height=3.8, fig.width=10, message=FALSE,echo=FALSE, warning=FALSE, include=TRUE, results='asis'} # Generate detailed visualizations for each field tryCatch({ # Merge field polygons for processing @@ -509,18 +509,24 @@ tryCatch({ dplyr::summarise(.groups = 'drop') # Generate plots for each field - purrr::walk(AllPivots_merged$field, function(field_name) { + for(i in seq_along(AllPivots_merged$field[1:3])) { + field_name <- AllPivots_merged$field[i] + tryCatch({ - cat("\n") # Add an empty line for better spacing + # Add page break before each field (except the first one) + if(i > 1) { + cat("\\newpage\n\n") + } - # Call ci_plot with explicit parameters + # Call ci_plot with explicit parameters (ci_plot will generate its own header) ci_plot( pivotName = field_name, field_boundaries = AllPivots0, current_ci = CI, ci_minus_1 = CI_m1, ci_minus_2 = CI_m2, - last_week_diff = last_week_dif_raster_abs, three_week_diff = three_week_dif_raster_abs, + last_week_diff = last_week_dif_raster_abs, + three_week_diff = three_week_dif_raster_abs, harvesting_data = harvesting_data, week = week, week_minus_1 = week_minus_1, @@ -529,7 +535,7 @@ tryCatch({ borders = borders ) - # cat("\n") + cat("\n\n") # Call cum_ci_plot with explicit parameters cum_ci_plot( @@ -539,15 +545,18 @@ tryCatch({ facet_on = FALSE ) + cat("\n\n") + }, error = function(e) { safe_log(paste("Error generating plots for field", field_name, ":", e$message), "ERROR") - cat(paste("## Error generating plots for field", field_name, "\n")) - cat(paste(e$message, "\n")) + cat("\\newpage\n\n") + cat("# Error generating plots for field ", field_name, "\n\n") + cat(e$message, "\n\n") }) - }) + } }, error = function(e) { safe_log(paste("Error in field visualization section:", e$message), "ERROR") - cat("Error generating field plots. See log for details.\n") + cat("Error generating field plots. See log for details.\n\n") }) ``` diff --git a/r_app/report_utils.R b/r_app/report_utils.R index 6b7dc7c..a17d94d 100644 --- a/r_app/report_utils.R +++ b/r_app/report_utils.R @@ -271,13 +271,13 @@ ci_plot <- function(pivotName, nrow = 1, widths = c(0.23, 0.18, 0.18, 0.18, 0.23)) # Output heading and map to R Markdown - cat(paste("## Field", pivotName, "-", age, "weeks after planting/harvest", "\n")) + cat(paste("## Field", pivotName, "-", age, "weeks after planting/harvest", "\n\n")) print(tst) }, error = function(e) { safe_log(paste("Error creating CI plot for pivot", pivotName, ":", e$message), "ERROR") - cat(paste("## Field", pivotName, "- Error creating visualization", "\n")) - cat(paste("Error:", e$message, "\n")) + cat(paste("# Field", pivotName, "- Error creating visualization", "\n\n")) + cat(paste("Error:", e$message, "\n\n")) }) } @@ -388,7 +388,7 @@ cum_ci_plot <- function(pivotName, ci_quadrant_data = CI_quadrant, plot_type = " } # Output plot to R Markdown with reduced height - subchunkify(g, 3.2, 10) # Reduced from 3.2 to 2.8 + subchunkify(g, 2.8, 10) # Reduced from 3.2 to 2.8 }, error = function(e) { safe_log(paste("Error creating CI trend plot for pivot", pivotName, ":", e$message), "ERROR")