Bacterial biophotons as non-local information carriers: Species-specific spectral characteristics of a stress response.

pacman::p_load(pacman, ggplot2, tidyr, dplyr, haven)

# Read SPSS data
my_data <- haven::read_sav("TESSARO_NONLOCAL_BACTERIA.sav")

# Convert the INJ column to a factor
my_data$INJ <- as.factor(my_data$INJ) 

# Convert columns to factors for ggplot compatibility
my_data$INJ <- as.factor(my_data$INJ) 
my_data$SPEINJ <- as.factor(my_data$SPEINJ)
my_data$SPERE <- as.factor(my_data$SPERE)

# --- Visualisations --- #

#  Baseline vs. Injection
ggplot(my_data, aes(x = INJ, y = WAVG, fill = INJ)) +
  geom_boxplot() +
  facet_wrap(~ CON, scales = "free_y") +
  labs(x = "Injection", y = "Average Biophoton Emission (WAVG)") +
  theme_minimal()

# Species-Specific Differences
ggplot(my_data, aes(x = SPEINJ, y = WAVG, color = SPERE, fill = INJ)) +
  geom_violin() +
  facet_wrap(~ CON, scales = "free") +
  labs(x = "Species Injected", y = "Average Biophoton Emission (WAVG)") +
  theme_minimal()

# Convert necessary columns to factors
my_data$INJ <- as.factor(my_data$INJ) 
my_data$SPEINJ <- as.factor(my_data$SPEINJ)
my_data$SPERE <- as.factor(my_data$SPERE)

#Baseline vs. Injection: Facet by Biophoton Measure
my_data %>%
  select(INJ, CON, WAVG, F1, F2, F3, F4) %>%
  pivot_longer(cols = c(WAVG, F1, F2, F3, F4), names_to = "BM", values_to = "value") %>%
  ggplot(aes(x = INJ, y = value, fill = INJ)) + 
  geom_boxplot() +
  facet_grid(BM ~ CON, scales = "free") + 
  labs(x = "Injection", y = "Biophoton Emission") + 
  theme_minimal()

# Check for columns with overlap
conflicting_cols <- names(which(sapply(my_data, function(x) any(is.factor(x))))) 

# Decide how to resolve conflicts (example: change factors to character types)
for (col in conflicting_cols) {
  my_data[, col] <- as.character(my_data[, col])
} 

my_data %>%
  select(INJ, CON, WAVG, F1, F2, F3, F4) %>%
  pivot_longer(cols = c(WAVG, F1, F2, F3, F4), names_to = "Biophoton_Measure", values_to = "Value") %>%
  ggplot(aes(x = Biophoton_Measure, y = Value)) +
  geom_boxplot() +
  facet_wrap(vars(INJ, CON), scales = "free") +
  theme()