```{r setup, include=FALSE}
knitr::opts_chunk$set(
  results = 'asis',
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  fig.align = 'center'
)

#Load libraries
library(tidyverse)
library(readxl)
library(gapminder)
library(kableExtra)
library(cowplot)
```


# Introduction
I am Geetha Perera, a Research Technician with Agriculture and Food based in Canberra. At present I am a part of the Soil Constraints research team in the Crops Program.  I had no experience in R before Data School, tried to self-learn but never happened.  I have been using Excel extensively to record, summarise and visualise data mostly using bar graphs.  My main aim in Data School FOCUS was to learn coding with R to replace the repetitive steps that I follow when working with data sets in Excel.  

# My Project
Aluminium toxicity is one of the main stresses to plants in acid soils which limits yields of major crops in Australia.    Use of aluminium resistant crops is one strategy to enable production in these soils in addition to soil management strategies such as liming. In a transgenic approach to increase the tolerance to aluminium in canola, transgenic canola lines have been produced in CSIRO by transforming the canola cultivar Oscar with two genes related to aluminium tolerance from wheat (_TaALMT1_) and/ or barely (_HvAACT1_).

Seedlings of T1 and T2 families of these transgenic lines were screened in a series of hydroponic experiments (Figure 1) to investigate the effect of aluminium on their early growth and to select any better performing lines for further screening.  In each screen, seedlings were grown in three concentrations of aluminium (0 µM, 5 µM and 10 µM) in a nutrient solution for two weeks and data on the length of the longest root (Figure 2), total root length (by scanning), shoot dry weight and root dry weight were collected. 

```{r echo=FALSE, out.width='50%', fig.cap="Setup of the hydroponic experiments"}
knitr::include_graphics('resources/img/setup.jpg')
```

```{r echo=FALSE, out.width='50%', fig.cap="Measuring the length of the longest root"}
knitr::include_graphics('resources/img/measure_root.jpg')
```

For the Data School project, I have used the data of one transgenic screen (Experiment 39) to summarise and visualise data with the aim of repeating this process in examining the data of the other screens. Seedlings of one T1 generation family (T1 3672-19) and its T2 generation family (T2 3672-19-1) with the cultivar Oscar (as the control) were screened in this particular experiment. 


## Preliminary results

Table 1 shows the format of the data after cleaning up, tidying and reorganising using R.


```{r tidy_data, eval=TRUE, results='hide'}

#tidying up data

long_root <- read_excel("data/experiment_39.xlsx", sheet="long_root")%>% 
  gather(treatment,longest_root, "0 µM", "5 µM", "10 µM") %>% 
  mutate(longest_root=as.numeric(longest_root))
long_root$treatment <- factor(long_root$treatment,levels = c("0 µM", "5 µM", "10 µM"))

long_root 

shoot_dw <- read_excel("data/experiment_39.xlsx", sheet="shoot_dw") %>% 
  gather(treatment,shoot_dw, "0 µM", "5 µM", "10 µM") %>% 
  mutate(shoot_dw=as.numeric(shoot_dw))
shoot_dw$treatment <- factor(shoot_dw$treatment,levels = c("0 µM", "5 µM", "10 µM"))

shoot_dw

root_dw <- read_excel("data/experiment_39.xlsx", sheet="root_dw") %>% 
  gather(treatment,root_dw,"0 µM", "5 µM", "10 µM")%>% 
  mutate(root_dw=as.numeric(root_dw))
root_dw$treatment <- factor(root_dw$treatment,levels = c("0 µM", "5 µM", "10 µM"))

root_dw 

root_length <- read_excel("data/experiment_39.xlsx", sheet="root_length") %>% 
  gather(treatment,root_length,"0 µM", "5 µM", "10 µM")%>% 
  mutate(root_length=as.numeric(root_length))
root_length$treatment <- factor(root_length$treatment,levels = c("0 µM", "5 µM", "10 µM"))
root_length

ex39_combined <- bind_cols(long_root,shoot_dw,root_dw,root_length) 
ex39_combined
view(ex39_combined)

# tidy data to be used for plots and analysis
ex39 <-select(ex39_combined,1,2,3,4,8,12,16) %>% 
  mutate(total_dw=shoot_dw+root_dw)%>% 
  filter(longest_root != "-",shoot_dw !="-", root_dw !="-", root_length!='_', total_dw != '-')
ex39
view (ex39)

```


```{r mytable, out.width='100%', echo = T}
ex39_data <- ex39 %>% 
  select(genotype, treatment, plant_no, longest_root, shoot_dw, root_dw, root_length, total_dw) %>% 
rename(`Line`= genotype, `Aluminium concentration` = treatment,`seedling number` = plant_no, 
`longest root length (mm)` 
= longest_root,`shoot dry weight (mg)` =shoot_dw,
`root dry weight (mg)`= root_dw,`total root length (cm)` = root_length, `total dry weight (mg)`= total_dw) 

knitr::kable(head(ex39_data, n = 5), format = "html", 
caption = "Seedling growth data after tidying up using R") %>% 
kable_styling("striped")
```

Raw data for dry weights, length of the longest root and total root length are shown using boxplots in Figures 3 and 4 respectively.  Showing data in this form helped to pick up the outliers easily and to see a broad picture of the response of each line to each level of aluminium. 

```{r, dry_weights, eval=TRUE, echo= FALSE, results='hide'}
# shoot dry weight

sdw <- ggplot(data=ex39, aes(x=genotype, y=shoot_dw, colour=treatment))+geom_boxplot()+facet_wrap(~treatment)

sdw_final <- sdw+
  labs(title="Shoot dry weight", x= "line name", y="shoot dry weight (mg)")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         strip.text = element_text(size = 8))


# root dry weight

rdw <- ggplot(data=ex39, aes(x=genotype, y=root_dw, colour=treatment))+geom_boxplot()+facet_wrap(~treatment)


rdw_final <- rdw+
  labs(title="Root dry weight", x= "line name", y="root dry weight (mg)")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         strip.text = element_text(size = 8))

# total dry weight

tdw <- ggplot(data=ex39, aes(x=genotype, y=total_dw, colour=treatment))+geom_boxplot()+facet_wrap(~treatment)

tdw_final <- tdw+
  labs(title="Total dry weight", x= "line name", y="total dry weight (mg)")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         strip.text = element_text(size = 8))
```


```{r 3, out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Dry weights",eval=TRUE, echo= FALSE, results='show'}

# final boxplot for dry weights 

final_plot_dw <- plot_grid(sdw_final+theme(legend.position ="none"), rdw_final+theme(legend.position ="none"), tdw_final+theme(legend.position ="none"),nrow = 1)
final_plot_dw
```


```{r, root_length, eval=TRUE, echo= FALSE, results='hide'}

# length of longest root

long_root<- ggplot(data=ex39, aes(x=genotype, y=longest_root, colour=treatment))+geom_boxplot()+facet_wrap(~treatment)

long_root_final <- long_root+
  labs(title="Length of the longest root", x= "line name", y="root length (mm)")+
  theme_bw()+
  theme (axis.text = element_text(size = 8, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 10),
         strip.text = element_text(size = 8))

rt_length <- ggplot(data=ex39, aes(x=genotype, y=root_length, colour=treatment))+geom_boxplot()+facet_wrap(~treatment)

rt_length_final <- rt_length+
  labs(title="Total root length", x= "line name", y="root length (cm)")+
  theme_bw()+
  theme (axis.text = element_text(size = 8, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 10),
         strip.text = element_text(size = 8))

```

```{r 4, out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Length of the longest root and total root length"}
# final boxplot for root lengths 

final_plot_rl <- plot_grid(long_root_final+theme(legend.position ="none"),rt_length_final+theme(legend.position ="none"))
final_plot_rl
```

Mean and standard error of each variable measured were calculated for each line at each concentration of aluminium (Figure 5 and Figure 6). Outliers were not removed before summarising the data as the individuals in T1 and T2 generations are still segregating. In general, none of the transgenic lines screened in this experiment performed better in the aluminium treatments when compared with the control. The T2 line showed slightly better root growth in 10 µM aluminium (Figure 6).

```{R, stats,eval=TRUE, results='hide'}

# Calculating means and standard error

ex39_stats <- ex39 %>%
  group_by(genotype, treatment) %>% 
  summarise (num_rows = n(),
             Avg_long_root = mean(longest_root),
             med_long_root= median(longest_root),
             sd_long_root=sd(longest_root),
             se_long_root=(sd_long_root)/sqrt(num_rows),
             Avg_shoot_dw = mean(shoot_dw),
             sd_shoot_dw=sd(shoot_dw),
             se_shoot_dw=(sd_shoot_dw)/sqrt(num_rows),
             Avg_root_dw = mean(root_dw),
             sd_root_dw=sd(root_dw),
             se_root_dw =(sd_root_dw)/sqrt(num_rows),
             Avg_root_length = mean(root_length),
             sd_root_length=sd(root_length), 
             se_root_length= (sd_root_length)/sqrt(num_rows),
             Avg_total_dw = mean(total_dw),
             sd_total_dw=sd(total_dw),
             se_total_dw= (sd_total_dw)/sqrt(num_rows))
```


```{r, mean_dry_weights, eval=TRUE, echo= FALSE, results='hide'}

# shoot dry weight

mean_sdw <- ex39_stats %>% 
  ggplot(aes(x = genotype,y = Avg_shoot_dw, colour=genotype))+
  geom_point(size=2)+
  geom_errorbar(aes(ymin=Avg_shoot_dw-se_shoot_dw, 
                    ymax=Avg_shoot_dw+se_shoot_dw),size=1)+
  facet_wrap(~treatment)

mean_sdw_final <- mean_sdw+labs(title="Shoot dry weight", x= "line name", y="shoot dry weight (mg)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 6),
         strip.text = element_text(size = 8))+
  ylim (0,50)                                               

# root dry weight

mean_rdw <- ex39_stats %>% 
  ggplot(aes(x = genotype,
             y = Avg_root_dw, colour=genotype))+
  geom_point(size=2)+
  geom_errorbar(aes(ymin=Avg_root_dw-se_root_dw, 
                    ymax=Avg_root_dw+se_root_dw),size=1)+
  facet_wrap(~treatment)

mean_rdw_final <- mean_rdw+labs(title="Root dry weight", x= "line name", y="root dry weight (mg)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 6),
         strip.text = element_text(size = 8))+
  ylim (0,50)                                                  

# total dry weight

mean_tdw <- ex39_stats %>% 
  ggplot(aes(x = genotype,y = Avg_total_dw, colour=genotype))+
  geom_point(size=2)+
  geom_errorbar(aes(ymin=Avg_total_dw-se_total_dw, 
                    ymax=Avg_total_dw+se_total_dw), size=1)+
  facet_wrap(~treatment)

mean_tdw_final <- mean_tdw+labs(title="Total dry weight", x= "line name", y="total dry weight (mg)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 6),
         strip.text = element_text(size = 8))+
  ylim (0,50)                                                
```

```{r 5, out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Mean dry weight"}
final_mean_dw_plot <- plot_grid(mean_sdw_final+theme(legend.position ="none"), mean_rdw_final+theme(legend.position ="none"), mean_tdw_final+theme(legend.position ="none"), nrow = 1, rel_widths = c (1,1)) 
final_mean_dw_plot
```

```{r, mean_root_lengths, eval=TRUE, echo= FALSE, results='hide'}

# length of the longest root

mean_long_root <- ex39_stats %>% 
  ggplot(aes(x = genotype, y = Avg_long_root, colour=genotype))+
  geom_point(size=2)+
  geom_errorbar(aes(ymin=Avg_long_root-sd_long_root, 
                    ymax=Avg_long_root+sd_long_root),size=1)+
  facet_wrap(~treatment)

mean_long_root_final <- mean_long_root +
  labs(title="Length of the longest root", x= "line name", y="root length (mm)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 6),
         strip.text = element_text(size = 8))+
  ylim(0,175)

mean_rt_length <- ex39_stats %>% 
  ggplot(aes(x = genotype,y = Avg_root_length, colour=genotype))+
  geom_point(size=2)+
  geom_errorbar(aes(ymin=Avg_root_length-se_root_length, 
                    ymax=Avg_root_length+se_root_length), size=1)+
  facet_wrap(~treatment)

mean_rt_length_final <- mean_rt_length+labs(title="Total root length", x= "line name", y="root length (cm)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 6, angle = 90),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 6),
         strip.text = element_text(size = 8))+
  ylim (0,150)                                 
```

```{r 6, out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Mean root length"}
# root lengths

final_mean_rl_plot <- plot_grid(mean_long_root_final+theme(legend.position ="none"), mean_rt_length_final+theme(legend.position ="none"),nrow = 1, rel_widths = c (1,1))

final_mean_rl_plot
```
The relationships between the total dry weight (the above ground variable measured) and the length of the longest root and the total root length (the two below ground variables measured) are shown in Figures 7 and 8 respectively.  Total root length seems to be a better variable to measure in comparison with the length of the longest root, as it shows a positive correlation to the dry weight in most instances (Figure 8). 

```{r 7, echo= TRUE,out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Length of the longest root vs total dry weight"}

# length of longest root vs total dry weight

lr_dw<- ggplot(data=ex39, aes(x=longest_root, y=total_dw, colour=genotype))+geom_point()+
  geom_smooth(method = "lm", size = 0.5, se=FALSE)+facet_wrap(~treatment)


lr_dw_final <- lr_dw+labs(x= "length of the longest root (mm)", y="total dry weight (mg)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 8),
         axis.title = element_text(size = 8),
         plot.title = element_text(size = 10),
         legend.title = element_text(size = 8),
         legend.text = element_text(size = 8),
         strip.text = element_text(size = 10))
lr_dw_final

```

```{r 8, out.width='60%', fig.align='center', fig.height= 4, fig.width=6, fig.cap="Total root length vs total dry weight"}

# root length vs total dry weight

rl_dw<- ggplot(data=ex39, aes(x=root_length, y=total_dw, colour=genotype))+geom_point()+
  geom_smooth(method = "lm", size = 0.5, se=FALSE)+facet_wrap(~treatment)

rl_dw_final <- rl_dw+labs(x= "total root length (cm)", y="total dry weight (mg)", colour="Line name")+
  theme_bw()+
  theme (axis.text = element_text(size = 8),
  axis.title = element_text(size = 8),
  plot.title = element_text(size = 10),
  legend.title = element_text(size = 8),
  legend.text = element_text(size = 8),
  strip.text = element_text(size = 10))

rl_dw_final
```

# My Digital Toolbox

I have been using R version `r getRversion()` for this project and the digital tools used were

* _tidyverse_
* _readxl_
* _ggplot2_ 
* _rmarkdown_
* _knitr_ and
* _kableExtra_

## Favourite tools

![](resources/img/tidyverse.png){width=110px}
![](resources/img/ggplot2.png){width=100px}



# My time went ...

I spent a reasonable time on tidying up the data.  Data of each variable were in a separate worksheet in Excel, I tempted to tidy them in Excel but read directly from Excel and tidied up in R instead. Visualising took longer than expected as I created various plots to select the ones to best visualise the data and I had to troubleshoot to get a code to run sometimes.

# Next steps

I will use the process that I developed in this project to look at the data of the other experiments done to screen GM canola for aluminium tolerance probably after modifying if necessary.
I am keen to learn more and practice regular expression, functions and statistical analysis using R.


# My Data School Experience

Data school FOCUS was a great learning experience for me and it was amazing to see how helpful R is for tidying up and visualising data.  The way the program has been structured and the support of the great teachers and the helpers made it much more enjoyable learning experience.  Applying the new skills that I learned to some of the data that I have collected in a project was also very exciting and I am looking forward to explore this data set more using R.
I will definitely use this knowledge and keep coding as a regular practice in my future projects.  We already started having conversations within our team on the use of coding as a regular practice and how we could share our knowledge among the team members.

# Acknowledgments

A huge thank you to Kerensa McElroy, Stephen Pearce and all the other instructors, for your continuous support and time to teach us, Kristian Goodacre for keeping us together and making sure that we are moving forward and Gordon McLachlan, Emmett Leyne and all the other helpers who dedicated their time. A special thank you to Gilbert Permalloo, my colleague and the personal helper for my project for encouraging me enrolling in this program and his help with the project and Manny Delhaize, my line manager and my team for supporting me to commit time for learning.   
