SEACAR Overall Comparison

Broad Comparisons of the Overall Datasets.
Code
library(here)
library(dplyr)
df_SEACAR <- readr::read_delim(
  here("data/Discrete WQ - 10006.txt"),
  delim = "|"
) %>%
# Convert ActivityDepth_m to numeric for plotting
mutate(ActivityDepth_m = as.numeric(ActivityDepth_m))


df_OLD <- readr::read_delim(here::here("data/allDataSEACAR.csv"), delim=",")
compare column names
c1 <- colnames(df_SEACAR)
c2 <- colnames(df_OLD)

comparison <- data.frame(
  column = union(c1, c2),
  in_SEACAR = union(c1, c2) %in% c1,
  in_OLD    = union(c1, c2) %in% c2
)

print(comparison)
                    column in_SEACAR in_OLD
1                    RowID      TRUE   TRUE
2                ProgramID      TRUE   TRUE
3              ProgramName      TRUE   TRUE
4                  Habitat      TRUE   TRUE
5              IndicatorID      TRUE   TRUE
6            IndicatorName      TRUE   TRUE
7              ParameterID      TRUE   TRUE
8            ParameterName      TRUE   TRUE
9           ParameterUnits      TRUE   TRUE
10             ResultValue      TRUE   TRUE
11              SampleDate      TRUE   TRUE
12                    Year      TRUE   TRUE
13                   Month      TRUE   TRUE
14     SEACAR_QAQCFlagCode      TRUE   TRUE
15 SEACAR_QAQC_Description      TRUE   TRUE
16                 Include      TRUE   TRUE
17              LocationID      TRUE  FALSE
18       ProgramLocationID      TRUE   TRUE
19     ProgramLocationName      TRUE  FALSE
20        OriginalLatitude      TRUE   TRUE
21       OriginalLongitude      TRUE   TRUE
22                  AreaID      TRUE   TRUE
23         ManagedAreaName      TRUE   TRUE
24             AreaID_Buff      TRUE  FALSE
25    ManagedAreaName_Buff      TRUE  FALSE
26         EstuarineMarine      TRUE  FALSE
27                   OIMMP      TRUE  FALSE
28                  CHIMMP      TRUE  FALSE
29             CoralRegion      TRUE  FALSE
30            ActivityType      TRUE   TRUE
31         ActivityDepth_m      TRUE   TRUE
32           RelativeDepth      TRUE   TRUE
33            TotalDepth_m      TRUE   TRUE
34                     MDL      TRUE   TRUE
35                     PQL      TRUE   TRUE
36           DetectionUnit      TRUE   TRUE
37          ValueQualifier      TRUE   TRUE
38    ValueQualifierSource      TRUE   TRUE
39          SampleFraction      TRUE  FALSE
40          ResultComments      TRUE   TRUE
41          SEACAR_EventID      TRUE   TRUE
42           ExportVersion      TRUE   TRUE
43                    ...1     FALSE   TRUE
44                   MADup     FALSE   TRUE
45                  Region     FALSE   TRUE
keep only columns of interest to avoid coltype errors
cols_of_interest <- c(
  "ProgramName", "ProgramLocationID", "OriginalLatitude", "OriginalLongitude", 
  "ActivityDepth_m", "ParameterUnits", "ResultValue", "SampleDate"
)
df_SEACAR <- df_SEACAR %>% select(all_of(cols_of_interest))
df_OLD <- df_OLD %>% select(all_of(cols_of_interest))
show time series of row counts for both datasets
library(ggplot2)
library(tidyr)
library(lubridate)

# Count rows per date for each dataset, bin by year
seacar_counts <- df_SEACAR %>%
  group_by(SampleDate = floor_date(SampleDate, "year")) %>%
  count(name = "SEACAR_Count") %>%
  ungroup()

old_counts <- df_OLD %>%
  group_by(SampleDate = floor_date(SampleDate, "year")) %>%
  count(name = "OLD_Count") %>%
  ungroup()

# Combine and plot
combined_counts <- full_join(seacar_counts, old_counts, by = "SampleDate") %>%
  arrange(SampleDate) %>%
  mutate(
    SEACAR_Count = replace_na(SEACAR_Count, 0),
    OLD_Count = replace_na(OLD_Count, 0)
  )

ggplot(combined_counts, aes(x = SampleDate)) +
  geom_line(aes(y = SEACAR_Count, color = "SEACAR_STD", linetype = "SEACAR_STD"), size = 1, alpha = 0.7) +
  geom_line(aes(y = OLD_Count, color = "OLD_STD", linetype = "OLD_STD"), size = 1, alpha = 0.7) +
  scale_y_log10() +
  scale_linetype_manual(values = c("SEACAR_STD" = "solid", "OLD_STD" = "solid")) +
  scale_color_manual(values = c("SEACAR_STD" = "blue", "OLD_STD" = "red")) +
  labs(
    title = "Row Count Over Time (Log Scale)",
    x = "Sample Date",
    y = "Number of Rows (log10)",
    color = "Dataset",
    linetype = "Dataset"
  ) +
  theme_minimal() +
  theme(legend.position = "bottom")

plot ActivityDepth_m
library(ggplot2)

if (nrow(df_SEACAR) == 0 || nrow(df_OLD) == 0) {
  cat("One or both dataframes are empty.\n")
} else {
  # Combine dataframes with a source column
  df_combined <- bind_rows(
    df_SEACAR %>% mutate(source = "SEACAR_STD"),
    df_OLD %>% mutate(source = "OLD_STD")
  )

  # Create split violin plot
  ggplot(df_combined, aes(x = source, y = ActivityDepth_m, fill = source)) +
    geom_violin(alpha = 0.6) +
    geom_boxplot(width = 0.2, alpha = 0.8, outlier.shape = NA) +
    scale_y_log10() +
    labs(
      title = "ActivityDepth_m Distribution Comparison (Log Scale)",
      x = "Dataset",
      y = "ActivityDepth_m (log10)"
    ) +
    theme_minimal() +
    theme(legend.position = "none")
}