---
title: "Supplementary.Figures"
author: "Lea Frey"
date: "4/29/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
libraries
```{r}
library(tidyverse)
library(scales)
```
#Supplementaryplot S1 allelfrequency distribution

```{r}


tiff(filename = 'Fig.S1.pdf', width = 174, height = 70, 
     units = 'mm', res = 300, compression = 'lzw')

par(mfrow=c(1,2))

hist(as.matrix(geno),
     main="",
xlab="Allele frequency",
ylab="Frequency",
xlim=c(0,1),
yaxp=c(0,8000000,2),
freq=T)
axis(2, at = c(0, 4000000, 8000000))

hist(as.matrix(tab10_5.t),
     main="b",
xlab="Allele frequency",
ylab="Frequency",
xlim=c(0,1),
ylim=c(0,8000000),
freq=T
)

dev.off()
#ggplot2
ggplot(data=, aes(x=cormean)) +
geom_histogram(color="dark gray", fill="gray",binwidth=5) +
 labs(title ="",
 x = "Survival rate (%)",
 y = "Number of accessions")
```
#Figure Suplementary Plot S2

```{r}
# LD decay ----------------------------------------------------------------


LDres <- 
  read.csv(file = 'LD_loess_results.csv', header = T, nrows = 100000) %>% 
  sapply(., class) %>% 
  read.csv(file = 'LD_loess_results.csv', header = T, colClasses = .)

tq <- c("#4477aa","#66ccee","#228833","#ccbb44","#ee6677","#aa3377","#bbbbbb")

# tags <- 
#   data.frame(chrB = c('LG1','LG2','LG3','LG4','LG5','LG6','LG7'),
#              lab = c('LG1','LG2','LG3','LG4','LG5','LG6','LG7'),
#              nx = c(3009769,3002130,3002156,3005871,3001043,3013234,3212284),
#              ny = c(0.0534,0.0343,0.0637,0.0400,0.0504,0.0384,0.0297),
#              nudx = c(1e5,1e5,1e5,-7e4,-7e4,-7e4,1e5),
#              nudy = c(0.1,0.1,0.1,-0.1,-0.1,-0.1,0.1))

LDres %>% 
  mutate(nX = round((dist - min(dist)) / (max(dist) - min(dist)), 4),
         nY = round((LD - min(LD)) / (max(LD) - min(LD)), 4)) %>%
  distinct( nX, nY, .keep_all = T )  %>%
  ungroup() %>% 
  # mutate(predGW = 
  #          loess(LD ~ dist, data = ., span = 0.75, family = 'gaussian') %>% 
  #          predict(.)) %>% 
  ggplot() +
  geom_point(aes(x = dist, y = LD), alpha = 0.5) +
  geom_line(aes(x = dist, y = pred), color = "red") +
  # geom_line(aes(x = dist, y = predGW), inherit.aes = T,
  #           linetype = 'dashed') +
  theme_bw(base_size = 13) +
  labs(x = 'Distance (bp)', y = expression("LD"*paste(" (", italic("r"))^{2}*")")) +
  # geom_label_repel(data = tags, aes(x = nx, y = ny, color = chrB, label = lab),
  #                  segment.alpha = 0.5, size = 3.5,
  #                  nudge_x = tags$nudx, nudge_y = tags$nudy) +
  theme(legend.position = 'none') +
  scale_x_continuous(labels = comma, limits = c(0, 2e5)) +
  scale_color_manual(values = tq) +
  facet_wrap(~ chrA)

ggsave(filename = 'LD_decay2.pdf', width = 170, height = 130, units = 'mm', bg = 'transparent')
```
#Supplemetary Figure S4
```{r}
#single spore inoculation
adj_means_one<-read.csv(file="adj_means_one.csv",header=T)
ap(adj_means_one)
ap(data.gwas)
data.gwas<-tibble::rownames_to_column(data.gwas,"AccID")
data.gwas1<-merge(adj_means_one,data.gwas,by="AccID")

tiff(filename = '', width = 60, height = 60, 
     units = 'mm', res = 300, compression = 'lzw')

 ggplot(data = data.gwas1, aes(x =, y = cormean)) + 
  geom_point(color='black',size=0.5) +
   ylim(-10, 100)+
   
    theme(panel.background=element_blank(),
        axis.line = element_line(size = 0.05, linetype = "solid",
                                 colour = "black"),
        axis.title.x=element_blank(),
        axis.title.y=element_blank())
 
dev.off()

sum(is.na(data.gwas))

#mixed spore inoculation
adj_means_all<-read.csv(file="adj_means_all.csv",header=T)
ap(adj_means_all)
ap(data.gwas)
data.gwas<-tibble::rownames_to_column(data.gwas,"AccID")
data.gwas1<-merge(adj_means_all,data.gwas,by="AccID")
ap(data.gwas1)

tiff(filename ='', width = 60, height = 60, 
     units = 'mm', res = 300, compression = 'lzw')

 ggplot(data = data.gwas1, aes(x = , y = predmean)) + 
  geom_point(color='black',size=0.5) +
   ylim(-10, 100)+
  #geom_smooth(method = "lm", se = FALSE,size=0.5,colour="black")+
    theme(panel.background=element_blank(),
        axis.line = element_line(size = 0.05, linetype = "solid",
                                 colour = "black"),
        axis.title.x=element_blank(),
        axis.title.y=element_blank())
dev.off()

#clover rot
adj_sclero<-read.csv(file="adj_means_sclero.csv",header=T)
ap(adj_sclero)

#delete Control
adj_sclero<-adj_sclero[-1,]
ap(data.gwas)
data.gwas<-tibble::rownames_to_column(data.gwas,"AccID")
data.gwas1<-merge(adj_sclero,data.gwas,by="AccID")
ap(data.gwas1)


tiff(filename = '', width = 60, height = 60, 
     units = 'mm', res = 300, compression = 'lzw')

 ggplot(data = data.gwas1, aes(x = , y = cormean)) + 
  geom_point(color='black',size=0.5) +
    ylim(0, 50)+
    theme(panel.background=element_blank(),
        axis.line = element_line(size = 0.05, linetype = "solid",
                                 colour = "black"),
        axis.title.x=element_blank(),
        axis.title.y=element_blank())

 dev.off()

```