Chapter 5 Phenotypic analysis

5.1 Phenotypic data analysis

In this section, simulated phenotypes are analyzed by fitting a linear mixed model and calculating Best Linear Unbiased Predictors (BLUPs) for each trait using the lme4 R package (Bates et al. 2020).

More information about lmer can be found here. Also, a brief introduction to linear mixed models can be found here.

Additional packages used in this section are data.table (Dowle and Srinivasan 2020), tidyverse (Wickham 2019), cowplot (Wilke 2020).

Load packages

Set working directory to where simulated phenotypes file is in workshop materials

Read in the simulated data

Check the structure of the data and change Genotype and rep to factors

Fit mixed model for low heritability trait and calculate BLUPs

Fit mixed model for high heritability trait and calculate BLUPs

Save BLUPs in a combined text file

Make Density histograms

## Density histogram of low heritability trait
p1 = ggplot(high_low, aes(x=Color_high_h2)) +
  geom_histogram(aes(y=..density..),position="identity", alpha=0.5, colour = "white")+
  geom_density(alpha=0, fill="white")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_high_h2,na.rm = TRUE)),linetype="dashed",colour = "#FF3721")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_high_h2,na.rm = TRUE)-sd(Color_high_h2,na.rm = TRUE)),linetype="dashed")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_high_h2,na.rm = TRUE)+sd(Color_high_h2,na.rm = TRUE)),linetype="dashed")+
  theme_classic(base_size = 18)+
  ylab("Density")+
  xlab("Seed redness (nm) High h2 BLUPs")+
  theme(plot.title = element_text(hjust = 0.5))
p1

## Density histogram of high heritability trait
p2 = ggplot(high_low, aes(x=Color_low_h2)) +
  geom_histogram(aes(y=..density..),position="identity", alpha=0.5, colour = "white")+
  geom_density(alpha=0, fill="white")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_low_h2,na.rm = TRUE)),linetype="dashed",colour = "#FF3721")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_low_h2,na.rm = TRUE)-sd(Color_low_h2,na.rm = TRUE)),linetype="dashed")+
  geom_vline(data=high_low, aes(xintercept=mean(Color_low_h2,na.rm = TRUE)+sd(Color_low_h2,na.rm = TRUE)),linetype="dashed")+
  theme_classic(base_size = 18)+
  ylab("Density")+
  xlab("Seed redness (nm) Low h2 BLUPs")+
  theme(plot.title = element_text(hjust = 0.5))
p2

## Combine the plots
library(cowplot)
combined_plot = plot_grid(p1,p2, ncol = 2, labels = c("A","B"),label_size=18,
                          label_fontfamily = 'serif',label_fontface = 'bold')

## Save plot in figures directory
setwd("~/PGRP_mapping_workshop/figures/phenotypes/")
pdf("WIDIV_942_simulated_pheno_distributions.pdf", width = 10, height = 4)
combined_plot
dev.off()

Note the greater variance among lines in (A) when simulating a high heritability trait compared to (B) with a low heritability. The red dash line is the mean +/- one standard deviation in black dashed lines.

References

Bates, Douglas, Martin Maechler, Ben Bolker, and Steven Walker. 2020. Lme4: Linear Mixed-Effects Models Using Eigen and S4. https://github.com/lme4/lme4/.

Dowle, Matt, and Arun Srinivasan. 2020. Data.table: Extension of ‘Data.frame‘. https://CRAN.R-project.org/package=data.table.

Wickham, Hadley. 2019. Tidyverse: Easily Install and Load the Tidyverse. https://CRAN.R-project.org/package=tidyverse.

Wilke, Claus O. 2020. Cowplot: Streamlined Plot Theme and Plot Annotations for Ggplot2. https://wilkelab.org/cowplot/.