S15.Rmd 5.16 KB
Newer Older
Kosmas Hench's avatar
Kosmas Hench committed
1 2
---
output: html_document
Kosmas Hench's avatar
Kosmas Hench committed
3
editor_options:
Kosmas Hench's avatar
Kosmas Hench committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
  chunk_output_type: console
---
# Supplementary Figure 15

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_knit$set(root.dir = './F_scripts')
```
## Summary

This is the accessory documentation of Supplementary Figure 15.

The Figure can be recreated by running the **R** script `S15.R`:

```sh
cd $WORK/3_figures/F_scripts

Rscript --vanilla S15.R
rm Rplots.pdf

```
## Details of `S15.R`

Kosmas Hench's avatar
Kosmas Hench committed
27 28
The S15.R script is a subset of the `F1.R` script run including data sets filtered for a minimum distance between the SNPs.
Is an executable R script that depends on the **tidyverse** package for data managing and plotting as well as on the **cowplot** package for plot composition.
Kosmas Hench's avatar
Kosmas Hench committed
29

Kosmas Hench's avatar
Kosmas Hench committed
30
It also depends on the helper script `F1.functions.R`.
Kosmas Hench's avatar
Kosmas Hench committed
31

Kosmas Hench's avatar
Kosmas Hench committed
32 33 34
```{r import, results='hide', message=FALSE, warning=FALSE}
library(tidyverse)
source("../../0_data/0_scripts/F1.functions.R")
Kosmas Hench's avatar
Kosmas Hench committed
35 36
```

Kosmas Hench's avatar
Kosmas Hench committed
37
### Setup
Kosmas Hench's avatar
Kosmas Hench committed
38

Kosmas Hench's avatar
Kosmas Hench committed
39
First, we load some metadata about the samples, define some colors and read in the PCA data for the three locations.
Kosmas Hench's avatar
Kosmas Hench committed
40

Kosmas Hench's avatar
Kosmas Hench committed
41 42 43
```{r setup_data, results='hide', message=FALSE, warning=FALSE}
dataAll <- read.csv('../../0_data/0_resources/F1.sample.txt',sep='\t') %>% 
  mutate(loc=substrRight(as.character(id),3))
Kosmas Hench's avatar
Kosmas Hench committed
44

Kosmas Hench's avatar
Kosmas Hench committed
45 46 47 48 49
cFILL <- rgb(.7,.7,.7)
ccc<-rgb(0,.4,.8)
clr<-c('#000000','#d45500','#000000')
fll<-c('#000000','#d45500','#ffffff')
eVclr <- c(rep('darkred',2),rep(cFILL,8))
Kosmas Hench's avatar
Kosmas Hench committed
50

Kosmas Hench's avatar
Kosmas Hench committed
51 52 53
belPCA <- readRDS('../../2_output/08_popGen/04_pca/bel_ld/belpca.Rds')
honPCA <- readRDS('../../2_output/08_popGen/04_pca/hon_ld/honpca.Rds')
panPCA <- readRDS('../../2_output/08_popGen/04_pca/pan_ld/panpca.Rds')
Kosmas Hench's avatar
Kosmas Hench committed
54 55
```

Kosmas Hench's avatar
Kosmas Hench committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
### Subplots

Then, for each location, we add the sample information and extract the amount of explains variation for the individual PCs.
We crate the x- and y-labels for the axis and plot the PCA

#### Honduras:

```{r hon, results='hide', message=FALSE, warning=FALSE}
dataHON <- cbind(dataAll %>% filter(sample=='sample',loc=='hon')%>% select(id,spec),
                 honPCA$scores); names(dataHON)[3:12]<- paste('PC',1:10,sep='')
exp_varHON <- (honPCA$singular.values[1:10])^2/length(honPCA$maf)
xlabHON <- paste('PC1 (',sprintf("%.1f",exp_varHON[1]*100),'%)')# explained varinace)')
ylabHON <- paste('PC2 (',sprintf("%.1f",exp_varHON[2]*100),'%)')# explained varinace)')
p1 <- ggplot(dataHON,aes(x=PC1,y=PC2,col=spec,fill=spec))+geom_point(size=1.1,shape=21)+
  scale_color_manual(values=clr,guide=F)+
  ggtitle('Honduras')+
  scale_fill_manual(values=fll,guide=F)+theme_mapK+
  theme(legend.position='bottom',plot.title = element_text(size = 11,hjust = .45),
        panel.border = element_rect(color=rgb(.9,.9,.9),fill=rgb(1,1,1,0)),
        plot.margin = unit(c(3,rep(5,3)),'pt'))+#coord_equal()+
  scale_x_continuous(name=xlabHON,breaks = c(-.3,.2))+
  scale_y_continuous(name=ylabHON,breaks = c(-.4,.4))
Kosmas Hench's avatar
Kosmas Hench committed
78 79
```

Kosmas Hench's avatar
Kosmas Hench committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#### Belize:

```{r bel, results='hide', message=FALSE, warning=FALSE}
dataBEL <- cbind(dataAll %>% filter(sample=='sample',loc=='bel') %>% select(id,spec),
                 belPCA$scores); names(dataBEL)[3:12]<- paste('PC',1:10,sep='')

exp_varBEL <- (belPCA$singular.values[1:10])^2/length(belPCA$maf)
xlabBEL <- paste('PC1 (',sprintf("%.1f",exp_varBEL[1]*100),'%)')
ylabBEL <- paste('PC2 (',sprintf("%.1f",exp_varBEL[2]*100),'%)')

p2 <- ggplot(dataBEL,aes(x=PC1,y=PC2,col=spec,fill=spec))+geom_point(size=1.1,shape=21)+
  scale_color_manual(values=clr,guide=F)+
  ggtitle('Belize')+
  scale_fill_manual(values=fll,guide=F)+theme_mapK+
  theme(legend.position='bottom',plot.title = element_text(size = 11,hjust = .45),
        panel.border = element_rect(color=rgb(.9,.9,.9),fill=rgb(1,1,1,0)),
        plot.margin = unit(c(3,rep(5,3)),'pt'))+
  scale_x_continuous(name=xlabBEL,breaks = c(-.15,.25))+
  scale_y_continuous(name=ylabBEL,breaks = c(-.35,.25))
```
Kosmas Hench's avatar
Kosmas Hench committed
100

Kosmas Hench's avatar
Kosmas Hench committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
#### Panama:

```{r pan, results='hide', message=FALSE, warning=FALSE}
dataPAN <- cbind(dataAll %>% filter(sample=='sample',loc=='boc',spec!='gum')%>% select(id,spec),
                 panPCA$scores); names(dataPAN)[3:12]<- paste('PC',1:10,sep='')
exp_varPAN <- (panPCA$singular.values[1:10])^2/length(panPCA$maf)
xlabPAN <- paste('PC1 (',sprintf("%.1f",exp_varPAN[1]*100),'%)')
ylabPAN <- paste('PC2 (',sprintf("%.1f",exp_varPAN[2]*100),'%)')
p3 <- ggplot(dataPAN,aes(x=PC1,y=PC2,col=spec,fill=spec))+geom_point(size=1.1,shape=21)+
  scale_color_manual(values=clr,guide=F)+
  ggtitle('Panama')+
  scale_fill_manual(values=fll,guide=F)+theme_mapK+
  theme(legend.position='bottom',plot.title = element_text(size = 11,hjust = .45),
        panel.border = element_rect(color=rgb(.9,.9,.9),fill=rgb(1,1,1,0)),
        plot.margin = unit(c(3,rep(5,3)),'pt'))+
  scale_x_continuous(name=xlabPAN,breaks = c(-.15,.2))+
  scale_y_continuous(name=ylabPAN,breaks = c(-.2,.2))
Kosmas Hench's avatar
Kosmas Hench committed
118 119
```

Kosmas Hench's avatar
Kosmas Hench committed
120
### Composition
Kosmas Hench's avatar
Kosmas Hench committed
121

Kosmas Hench's avatar
Kosmas Hench committed
122 123 124 125
Using the **cowplot** package we put together the final figure.

```{r combo, results='hide', message=FALSE, warning=FALSE}
S15 <- cowplot::plot_grid(p2, p1, p3, nrow = 1, labels = letters[1:3])
Kosmas Hench's avatar
Kosmas Hench committed
126 127
```

Kosmas Hench's avatar
Kosmas Hench committed
128
The Figure is then exported using `ggsave()`:
Kosmas Hench's avatar
Kosmas Hench committed
129

Kosmas Hench's avatar
Kosmas Hench committed
130 131
```{r, eval=FALSE}
ggsave(plot = S15,filename = '../output/S15.pdf',width = 183,height = 63,units = 'mm',device = cairo_pdf)
Kosmas Hench's avatar
Kosmas Hench committed
132 133
```

Kosmas Hench's avatar
Kosmas Hench committed
134

Kosmas Hench's avatar
Kosmas Hench committed
135
<center>
Kosmas Hench's avatar
Kosmas Hench committed
136
```{r f1SHOW, echo=FALSE, fig.height=63*0.03937008, fig.width=183*0.03937008}
Kosmas Hench's avatar
Kosmas Hench committed
137 138 139 140
S15
```
</center>
---