library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
### Data set
library(readxl)
whdataset2<- read_excel("C:\\Users\\jasra\\Downloads\\whdataset2.xlsx")
### Mean plant height at Site 3
library(dplyr)
SiteCode<- whdataset2$SiteCode
PlantHeight<-whdataset2$PlantHeight
Site_3<- filter(whdataset2, SiteCode == "Site 3")
mean_height_site3 <- mean(whdataset2$PlantHeight[whdataset2$SiteCode == "Site 3"], na.rm = TRUE)
View(mean_height_site3)
print(paste("Mean plant height at Site 3:", round(mean_height_site3, 2), "cm"))
## [1] "Mean plant height at Site 3: 107.33 cm"
### ggplot Thousand Grain Weight Variation by Site and Period
library(ggplot2)
ggplot(whdataset2, aes(x = SiteCode, y = ThousandGrainWeight, fill = Period)) +
geom_boxplot(alpha = 0.8) +
scale_fill_manual(values = c("Pre-1970" = "skyblue", "Post-1970" = "maroon")) +
labs(
x = "Site of Trial",
y = "Thousand Grain Weight (g)",
title = "Thousand Grain Weight Variation by Site and Period"
) +
theme_classic()

### Plant Height Comparison: SNP 5 AA vs GG Genotypes
SNP_5<- whdataset2$SNP_5
ggplot(whdataset2, aes(x = SNP_5, y = PlantHeight, fill = SNP_5)) +
geom_boxplot(alpha = 0.8, width = 0.6) +
labs(
x = "SNP 5 Genotype",
y = "Plant Height (cm)",
title = "Plant Height Comparison: SNP 5 AA vs GG Genotypes",
) +
scale_fill_manual(values = c("AA" = "lightblue", "GG" = "lightgreen")) +
theme_minimal()

### T test
plant_heightSNP5 <- whdataset2 %>%
select(PlantHeight, SNP_5) %>%
filter(!is.na(PlantHeight) & !is.na(SNP_5))
aa_data <- plant_heightSNP5 %>% filter(SNP_5 == "AA")
gg_data <- plant_heightSNP5 %>% filter(SNP_5 == "GG")
t_test_result <- t.test(PlantHeight ~ SNP_5,
data = plant_heightSNP5 %>%
filter(SNP_5 %in% c("AA", "GG")))
t_test_result
##
## Welch Two Sample t-test
##
## data: PlantHeight by SNP_5
## t = 0.18131, df = 130.99, p-value = 0.8564
## alternative hypothesis: true difference in means between group AA and group GG is not equal to 0
## 95 percent confidence interval:
## -3.581054 4.303721
## sample estimates:
## mean in group AA mean in group GG
## 99.03733 98.67600
print(t_test_result)
##
## Welch Two Sample t-test
##
## data: PlantHeight by SNP_5
## t = 0.18131, df = 130.99, p-value = 0.8564
## alternative hypothesis: true difference in means between group AA and group GG is not equal to 0
## 95 percent confidence interval:
## -3.581054 4.303721
## sample estimates:
## mean in group AA mean in group GG
## 99.03733 98.67600