Load the necessary packages

library(readxl)
library(ggplot2)

Import the data from the Excel file

data <- read_excel("/Users/jal4510/Desktop/MRes/Applied Crop Sciences/SPAD_PPFD_FW.xlsx", sheet = "RED+BLUE")

View the first few rows of the data to confirm it’s loaded correctly

head(data)
# A tibble: 6 × 4
  `Plant Tube`  PPFD  SPAD    FW
  <chr>        <dbl> <dbl> <dbl>
1 A             141.  44      84
2 A             265.  33      24
3 A             202.  34.8    20
4 B             151.  28      92
5 B             319.  29.8    20
6 B             241.  22.8    46
summary(data)
  Plant Tube             PPFD            SPAD            FW       
 Length:12          Min.   :138.4   Min.   :22.4   Min.   :13.00  
 Class :character   1st Qu.:151.1   1st Qu.:23.2   1st Qu.:20.00  
 Mode  :character   Median :221.8   Median :27.8   Median :26.00  
                    Mean   :232.0   Mean   :28.5   Mean   :43.25  
                    3rd Qu.:278.4   3rd Qu.:30.6   3rd Qu.:60.75  
                    Max.   :413.6   Max.   :44.0   Max.   :99.00  

Select columns X and Y for the correlation test

Perform Pearson correlation test

# Select columns for the correlation test
x <- data$PPFD
y <- data$SPAD
z <- data$FW

# Perform Pearson correlation tests for each pair of variables
cor_test_ppfd_spad <- cor.test(x, y)  # Correlation between PPFD and SPAD
cor_test_ppfd_fw <- cor.test(x, z)   # Correlation between PPFD and FW
cor_test_spad_fw <- cor.test(y, z)   # Correlation between SPAD and FW


# Print the correlation test results
print(cor_test_ppfd_spad)

    Pearson's product-moment correlation

data:  x and y
t = -1.4371, df = 10, p-value = 0.1812
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.7981248  0.2100443
sample estimates:
       cor 
-0.4137304 
print(cor_test_ppfd_fw)

    Pearson's product-moment correlation

data:  x and z
t = -3.08, df = 10, p-value = 0.01164
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.9080289 -0.2065196
sample estimates:
       cor 
-0.6977255 
print(cor_test_spad_fw)

    Pearson's product-moment correlation

data:  y and z
t = 1.3013, df = 10, p-value = 0.2223
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.247376  0.783367
sample estimates:
      cor 
0.3805524 

Create a scatter plot with a linear regression line

# Create a scatter plot with a linear regression line, encoding FW with color
ggplot(data, aes(x = FW, y = PPFD, color = FW)) +
  geom_point() +  # Create scatter plot
  geom_smooth(method = "lm", se = FALSE, color = "navy") +  # Add linear regression line
  labs(
    title = paste("Scatter Plot of PPFD vs. FW\nCorrelation = ", round(cor(data$PPFD, data$FW), 2),
                  "\nP-value = ", round(cor_test_ppfd_spad$p.value, 4)),
    x = "PPFD",
    y = "FW"
  ) +
  theme_minimal() +
  scale_color_gradient(low = "blue", high = "red")  # Color gradient for FW
`geom_smooth()` using formula = 'y ~ x'

For One-Way Anova

# If you're interested in grouping 'PPFD' by different ranges of SPAD, consider discretizing SPAD.
# For example, here, I'll bin SPAD into categories for illustration
data$FW_group <- cut(data$FW, breaks = 3, labels = c("Low", "Medium", "High"))
print(data)
# A tibble: 12 × 5
   `Plant Tube`  PPFD  SPAD    FW FW_group
   <chr>        <dbl> <dbl> <dbl> <fct>   
 1 A             141.  44      84 High    
 2 A             265.  33      24 Low     
 3 A             202.  34.8    20 Low     
 4 B             151.  28      92 High    
 5 B             319.  29.8    20 Low     
 6 B             241.  22.8    46 Medium  
 7 C             151.  27.6    53 Medium  
 8 C             319.  23.2    13 Low     
 9 C             241.  22.4    27 Low     
10 D             200.  23.2    16 Low     
11 D             414.  24      25 Low     
12 D             138.  29.2    99 High    
# Perform One-Way ANOVA: PPFD as response and SPAD group as factor
anova_result <- aov(PPFD ~ FW_group, data = data)

# Step 4: View the ANOVA table to see if there's a significant difference
summary(anova_result)
            Df Sum Sq Mean Sq F value Pr(>F)  
FW_group     2  42240   21120    4.85 0.0372 *
Residuals    9  39195    4355                 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# Step 5: (Optional) Perform a Tukey post-hoc test if ANOVA is significant
# Tukey's test is useful for pairwise comparison of groups
tukey_result <- TukeyHSD(anova_result)

summary(tukey_result)
         Length Class  Mode   
FW_group 12     -none- numeric
# Step 6: Create a boxplot to visualize the group differences
ggplot(data, aes(x = FW_group, y = PPFD, fill = FW_group)) +
  geom_boxplot() +
  labs(title = "One-Way ANOVA: SPAD Group vs PPFD",
       x = " FW Group",
       y = "PPFD") +
  theme_minimal()

FOR SUNLIGHT

# Load the necessary packages
library(readxl)
library(ggplot2)

# Import the data from the Excel file
data <- read_excel("/Users/jal4510/Desktop/MRes/Applied Crop Sciences/SPAD_PPFD_FW.xlsx", sheet = "Sunlight")

# View the first few rows of the data to confirm it's loaded correctly
head(data)
# A tibble: 6 × 4
  `Plant Tube` PPFD   SPAD    FW
  <chr>        <chr> <dbl> <dbl>
1 A            23.75  20       1
2 A            11.25  27       4
3 A            16.25  12.2     1
4 A            14.5   15.8     1
5 B            31.5   11.5     1
6 B            23.75  17.5     2
summary(data)
  Plant Tube            PPFD                SPAD             FW       
 Length:16          Length:16          Min.   :10.00   Min.   :0.500  
 Class :character   Class :character   1st Qu.:15.06   1st Qu.:0.975  
 Mode  :character   Mode  :character   Median :17.55   Median :1.000  
                                       Mean   :18.04   Mean   :1.219  
                                       3rd Qu.:20.70   3rd Qu.:1.000  
                                       Max.   :27.00   Max.   :4.000  
# Select columns for the correlation test
data$PPFD <- as.numeric(data$PPFD)
Warning: NAs introduced by coercion
x <- data$PPFD
y <- data$SPAD
z <- data$FW

# Perform Pearson correlation tests for each pair of variables
cor_test_ppfd_spad <- cor.test(x, y)  # Correlation between PPFD and SPAD
cor_test_ppfd_fw <- cor.test(x, z)   # Correlation between PPFD and FW
cor_test_spad_fw <- cor.test(y, z)   # Correlation between SPAD and FW

# Print the correlation test results
print(cor_test_ppfd_spad)

    Pearson's product-moment correlation

data:  x and y
t = -0.37296, df = 13, p-value = 0.7152
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.5843546  0.4321487
sample estimates:
       cor 
-0.1028916 
print(cor_test_ppfd_fw)

    Pearson's product-moment correlation

data:  x and z
t = -2.3707, df = 13, p-value = 0.03389
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.82849325 -0.05168065
sample estimates:
       cor 
-0.5493987 
print(cor_test_spad_fw)

    Pearson's product-moment correlation

data:  y and z
t = 1.1058, df = 14, p-value = 0.2874
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.2469797  0.6831509
sample estimates:
      cor 
0.2834251 
# Create a scatter plot with a linear regression line, encoding FW with color
ggplot(data, aes(x = PPFD, y = FW, color = FW)) +
  geom_point() +  # Create scatter plot
  geom_smooth(method = "lm", se = FALSE, color = "navy") +  # Add linear regression line
  labs(
    title = paste("Scatter Plot of PPFD vs. FW\nCorrelation = ", round(cor(data$PPFD, data$FW), 2),
                  "\nP-value = ", round(cor_test_ppfd_fw$p.value, 4)),  # Use correct p-value
    x = "PPFD",
    y = "FW"
  ) +
  theme_minimal() +
  scale_color_gradient(low = "blue", high = "red")  # Color gradient for FW
`geom_smooth()` using formula = 'y ~ x'
Warning: Removed 1 row containing non-finite outside the scale range
(`stat_smooth()`).
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_point()`).

# One-Way ANOVA: Group FW into categories
data$FW_group <- cut(data$FW, breaks = 3, labels = c("Low", "Medium", "High"))
print(data)
# A tibble: 16 × 5
   `Plant Tube`  PPFD  SPAD    FW FW_group
   <chr>        <dbl> <dbl> <dbl> <fct>   
 1 A             23.8  20     1   Low     
 2 A             11.2  27     4   High    
 3 A             16.2  12.2   1   Low     
 4 A             14.5  15.8   1   Low     
 5 B             31.5  11.5   1   Low     
 6 B             23.8  17.5   2   Medium  
 7 B             26    10     2   Medium  
 8 B             25    16     1   Low     
 9 C             31.5  22.8   1   Low     
10 C             23.8  26.6   1   Low     
11 C             26    13     0.9 Low     
12 C             25    17.6   0.6 Low     
13 D             32    24.4   1   Low     
14 D             NA    19.6   0.5 Low     
15 D             43.8  17     0.5 Low     
16 D             35.4  17.6   1   Low     
# Perform One-Way ANOVA: PPFD as response and FW_group as factor
anova_result <- aov(PPFD ~ FW_group, data = data)

# View the ANOVA table to see if there's a significant difference
summary(anova_result)
            Df Sum Sq Mean Sq F value Pr(>F)
FW_group     2  242.3  121.17   2.023  0.175
Residuals   12  718.7   59.89               
1 observation deleted due to missingness
# Optional: Perform a Tukey post-hoc test if ANOVA is significant
tukey_result <- TukeyHSD(anova_result)
summary(tukey_result)
         Length Class  Mode   
FW_group 12     -none- numeric
# Create a boxplot to visualize the group differences
ggplot(data, aes(x = FW_group, y = PPFD, fill = FW_group)) +
  geom_boxplot() +
  labs(title = "One-Way ANOVA: FW Group vs PPFD",
       x = "FW Group",
       y = "PPFD") +
  theme_minimal()
Warning: Removed 1 row containing non-finite outside the scale range
(`stat_boxplot()`).

For Nutrient

Load the necessary packages

library(readxl)
library(ggplot2)

Import the data from the Excel file

data <- read_excel("/Users/jal4510/Desktop/MRes/Applied Crop Sciences/SPAD_PPFD_FW.xlsx", sheet = "Nutrient")

View the first few rows of the data to confirm it’s loaded correctly

head(data)
# A tibble: 6 × 4
  Treatment  PPFD  SPAD    FW
      <dbl> <dbl> <dbl> <dbl>
1         1  43.2  19.1   1.2
2         1  43.2  17.2   1.2
3         2  41.7  21.5   2.2
4         2  41.7  24     2.2
5         3  45.6  19.6   2.4
6         3  45.6  20     2.4
summary(data)
   Treatment         PPFD            SPAD             FW       
 Min.   :1.00   Min.   :34.40   Min.   :17.25   Min.   :1.000  
 1st Qu.:2.75   1st Qu.:40.20   1st Qu.:20.82   1st Qu.:1.583  
 Median :4.50   Median :41.55   Median :23.40   Median :2.300  
 Mean   :4.50   Mean   :41.17   Mean   :23.52   Mean   :2.176  
 3rd Qu.:6.25   3rd Qu.:43.48   3rd Qu.:25.23   3rd Qu.:2.800  
 Max.   :8.00   Max.   :45.60   Max.   :32.60   Max.   :3.100  

Select columns X and Y for the correlation test

Perform Pearson correlation test

# Select columns for the correlation test
data$PPFD <- as.numeric(data$PPFD)
x <- data$PPFD
y <- data$SPAD
z <- data$FW

# Perform Pearson correlation tests for each pair of variables
cor_test_ppfd_spad <- cor.test(x, y)  # Correlation between PPFD and SPAD
cor_test_ppfd_fw <- cor.test(x, z)   # Correlation between PPFD and FW
cor_test_spad_fw <- cor.test(y, z)   # Correlation between SPAD and FW

# Print the correlation test results
print(cor_test_ppfd_spad)

    Pearson's product-moment correlation

data:  x and y
t = -4.1433, df = 14, p-value = 0.0009945
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.9049448 -0.3899008
sample estimates:
       cor 
-0.7421638 
print(cor_test_ppfd_fw)

    Pearson's product-moment correlation

data:  x and z
t = 1.8752, df = 14, p-value = 0.08178
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.06126951  0.77223697
sample estimates:
      cor 
0.4480436 
print(cor_test_spad_fw)

    Pearson's product-moment correlation

data:  y and z
t = -0.71749, df = 14, p-value = 0.4849
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.6256264  0.3390293
sample estimates:
       cor 
-0.1883258 

Create a scatter plot with a linear regression line

# Create a scatter plot with a linear regression line, encoding FW with color
ggplot(data, aes(x = PPFD, y = FW, color = FW)) +
  geom_point() +  # Create scatter plot
  geom_smooth(method = "lm", se = FALSE, color = "blue") +  # Add linear regression line
  labs(
    title = paste("Scatter Plot of PPFD vs. SPAD\nCorrelation = ", round(cor(x, y), 2),
                  "\nP-value = ", round(cor_test_ppfd_spad$p.value, 4)),
    x = "PPFD",
    y = "FW"
  ) +
  theme_minimal() +
  scale_color_gradient(low = "blue", high = "red")  # Color gradient for FW
`geom_smooth()` using formula = 'y ~ x'

For One-Way Anova

# If you're interested in grouping 'PPFD' by different ranges of SPAD, consider discretizing SPAD.
# For example, here, I'll bin SPAD into categories for illustration
data$FW_group <- cut(data$FW, breaks = 3, labels = c("Low", "Medium", "High"))
print(data)
# A tibble: 16 × 5
   Treatment  PPFD  SPAD    FW FW_group
       <dbl> <dbl> <dbl> <dbl> <fct>   
 1         1  43.2  19.1  1.2  Low     
 2         1  43.2  17.2  1.2  Low     
 3         2  41.7  21.5  2.2  Medium  
 4         2  41.7  24    2.2  Medium  
 5         3  45.6  19.6  2.4  Medium  
 6         3  45.6  20    2.4  Medium  
 7         4  44.3  21.1  3.1  High    
 8         4  44.3  23    3.1  High    
 9         5  41.4  23.3  3.1  High    
10         5  41.4  23.5  3.1  High    
11         6  41    23.6  2.7  High    
12         6  41    27.5  2.7  High    
13         7  37.8  25.6  1    Low     
14         7  37.8  32.6  1    Low     
15         8  34.4  25.1  1.71 Medium  
16         8  34.4  29.6  1.71 Medium  
# Perform One-Way ANOVA: PPFD as response and SPAD group as factor
anova_result <- aov(PPFD ~ FW_group, data = data)

# Step 4: View the ANOVA table to see if there's a significant difference
summary(anova_result)
            Df Sum Sq Mean Sq F value Pr(>F)
FW_group     2  10.76   5.382   0.408  0.673
Residuals   13 171.43  13.187               
# Step 5: (Optional) Perform a Tukey post-hoc test if ANOVA is significant
# Tukey's test is useful for pairwise comparison of groups
tukey_result <- TukeyHSD(anova_result)

summary(tukey_result)
         Length Class  Mode   
FW_group 12     -none- numeric
# Step 6: Create a boxplot to visualize the group differences
ggplot(data, aes(x = FW_group, y = PPFD, fill = FW_group)) +
  geom_boxplot() +
  labs(title = "One-Way ANOVA: SPAD Group vs PPFD",
       x = " FW Group",
       y = "PPFD") +
  theme_minimal()

For Red+Blue vs Sunlight

# Load the necessary packages
library(readxl)
library(ggplot2)

# Import the data from the Excel file
data <- read_excel("/Users/jal4510/Desktop/MRes/Applied Crop Sciences/SPAD_PPFD_FW.xlsx", sheet = "RED+BLUE vs Sunlight")

# View the first few rows of the data to confirm it's loaded correctly
head(data)
# A tibble: 6 × 7
  `Plant Tube`  PPFD  SPAD    FW PPFD_Sunlight SPAD_Sunlight FW_Sunlight
  <chr>        <dbl> <dbl> <dbl> <chr>                 <dbl>       <dbl>
1 A             141.  44    141. 23.75                  20             1
2 A             265.  33    265. 11.25                  27             4
3 A             202.  34.8  202. 16.25                  12.2           1
4 B             151.  28    151. 31.5                   11.5           1
5 B             319.  29.8  319. 23.75                  17.5           2
6 B             241.  22.8  241. 26                     10             2
summary(data)
  Plant Tube             PPFD            SPAD            FW       
 Length:12          Min.   :138.4   Min.   :22.4   Min.   :138.4  
 Class :character   1st Qu.:151.1   1st Qu.:23.2   1st Qu.:151.1  
 Mode  :character   Median :221.8   Median :27.8   Median :221.8  
                    Mean   :232.0   Mean   :28.5   Mean   :232.0  
                    3rd Qu.:278.4   3rd Qu.:30.6   3rd Qu.:278.4  
                    Max.   :413.6   Max.   :44.0   Max.   :413.6  
 PPFD_Sunlight      SPAD_Sunlight    FW_Sunlight   
 Length:12          Min.   :10.00   Min.   :0.500  
 Class :character   1st Qu.:12.81   1st Qu.:0.975  
 Mode  :character   Median :18.55   Median :1.000  
                    Mean   :18.47   Mean   :1.325  
                    3rd Qu.:23.20   3rd Qu.:1.250  
                    Max.   :27.00   Max.   :4.000  
# Select columns for the correlation test
x <- data$FW
y <- data$FW_Sunlight


# Perform Pearson correlation tests for each pair of variables
cor_test_FW_FW_Sunlight <- cor.test(x, y)  

# Print the correlation test results
print(cor_test_FW_FW_Sunlight)

    Pearson's product-moment correlation

data:  x and y
t = 0.52635, df = 10, p-value = 0.6101
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.4523372  0.6745295
sample estimates:
      cor 
0.1641868 
# Create the FW_group column to categorize the 'FW' variable into 3 groups
data$FW_group <- cut(data$FW, breaks = 3, labels = c("Low", "Medium", "High"))
print(data)
# A tibble: 12 × 8
   `Plant Tube`  PPFD  SPAD    FW PPFD_Sunlight SPAD_Sunlight FW_Sunlight
   <chr>        <dbl> <dbl> <dbl> <chr>                 <dbl>       <dbl>
 1 A             141.  44    141. 23.75                  20           1  
 2 A             265.  33    265. 11.25                  27           4  
 3 A             202.  34.8  202. 16.25                  12.2         1  
 4 B             151.  28    151. 31.5                   11.5         1  
 5 B             319.  29.8  319. 23.75                  17.5         2  
 6 B             241.  22.8  241. 26                     10           2  
 7 C             151.  27.6  151. 31.5                   22.8         1  
 8 C             319.  23.2  319. 23.75                  26.6         1  
 9 C             241.  22.4  241. 26                     13           0.9
10 D             200.  23.2  200. 32                     24.4         1  
11 D             414.  24    414. 39,75                  19.6         0.5
12 D             138.  29.2  138. 43.75                  17           0.5
# ℹ 1 more variable: FW_group <fct>
# Create the FW_Sunlight_Group column (same as FW_group but using FW for sunlight exposure categorization)
data$FW_Sunlight_Group <- cut(data$FW, breaks = 3, labels = c("Low", "Medium", "High"))
print(data)
# A tibble: 12 × 9
   `Plant Tube`  PPFD  SPAD    FW PPFD_Sunlight SPAD_Sunlight FW_Sunlight
   <chr>        <dbl> <dbl> <dbl> <chr>                 <dbl>       <dbl>
 1 A             141.  44    141. 23.75                  20           1  
 2 A             265.  33    265. 11.25                  27           4  
 3 A             202.  34.8  202. 16.25                  12.2         1  
 4 B             151.  28    151. 31.5                   11.5         1  
 5 B             319.  29.8  319. 23.75                  17.5         2  
 6 B             241.  22.8  241. 26                     10           2  
 7 C             151.  27.6  151. 31.5                   22.8         1  
 8 C             319.  23.2  319. 23.75                  26.6         1  
 9 C             241.  22.4  241. 26                     13           0.9
10 D             200.  23.2  200. 32                     24.4         1  
11 D             414.  24    414. 39,75                  19.6         0.5
12 D             138.  29.2  138. 43.75                  17           0.5
# ℹ 2 more variables: FW_group <fct>, FW_Sunlight_Group <fct>
# Perform pairwise t-tests between the groups for 'PPFD' as the response variable
# Using 'FW_Sunlight_Group' as the factor for grouping
t_test_result_FW <- pairwise.t.test(data$PPFD, data$FW_Sunlight_Group)

# Print the pairwise t-test results with adjusted p-values
print(t_test_result_FW)

    Pairwise comparisons using t tests with pooled SD 

data:  data$PPFD and data$FW_Sunlight_Group 

       Low     Medium 
Medium 0.00082 -      
High   0.00026 0.00551

P value adjustment method: holm