@@ -417,13 +417,26 @@ plot_pvo <- function(gc, ylim = NULL, text_multiplier = NULL, marker_size = 3) {
417
417
plot_subannual <- function (gc , ylim = NULL , text_multiplier = NULL ) {
418
418
colours <- get_colour_palette(length(names(gc )))
419
419
colours <- setNames(colours , names(gc ))
420
- agg <- DGVMTools :: aggregateYears(gc )
421
- # plt <- DGVMTools::plotSubannual(gc, col.by = "Layer"
422
- # , summary.function = mean
423
- # , title = NULL, subtitle = NULL, point.size = 0, cols = colours
424
- # , text.multiplier = text_multiplier, summary.only = TRUE
425
- # , summary.as.points = FALSE)
426
- df_long <- tidyr :: pivot_longer(agg @ data , cols = names(gc )
420
+
421
+ # Process each layer separately to handle NAs correctly
422
+ agg_data <- NULL
423
+ for (layer_name in names(gc )) {
424
+ # Create a temporary gc with just this layer
425
+ temp_gc <- DGVMTools :: selectLayers(gc , layer_name )
426
+ temp_gc @ data <- temp_gc @ data [! is.na(temp_gc @ data [[layer_name ]]), ]
427
+ # Aggregate this layer
428
+ agg_result <- DGVMTools :: aggregateYears(temp_gc )
429
+ # layer_results[[layer_name]] <- agg_result@data[[layer_name]]
430
+ if (is.null(agg_data )) {
431
+ agg_data <- agg_result
432
+ } else {
433
+ agg_data <- DGVMTools :: copyLayers(agg_result , agg_data , layer_name )
434
+ }
435
+ }
436
+
437
+ # Combine results into a data frame
438
+ # Create the plot using the combined data
439
+ df_long <- tidyr :: pivot_longer(agg_data @ data , cols = names(gc )
427
440
, names_to = " variable"
428
441
, values_to = " value" )
429
442
plt <- ggplot2 :: ggplot(df_long , aes(x = Day , y = value , color = variable )) +
0 commit comments