F5.Rmd 3.38 KB
Newer Older
1 2 3
---
output: html_document
editor_options: 
Kosmas Hench's avatar
Kosmas Hench committed
4
  chunk_output_type: console
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
---
# Figure 5
  
```{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 Figure 5.

The Figure can be recreated by runing the **R** script F5.R:

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

Rscript --vanilla F5.R
rm Rplots.pdf

Kosmas Hench's avatar
Kosmas Hench committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
```
## Details of F5.R

In the following, the individual steps of the R script are documented.
Is an executable R script that depends on a variety of image manipulation and data managing and genomic data packages.

It Furthermore depends on the R scripts `F4.functions.R` (located under `$WORK/0_data/0_scripts`).

This script is a modification of sript F4.R. It uses the same funtions and just differs in the data sets and settings 

```{r head,results='hide',message=FALSE}
library(tidyverse)
library(scales)
library(cowplot)
library(grid)
library(gridSVG)
library(grImport2)
source('../../0_data/0_scripts/F4.functions.R')
```

The script `F4.functions.R`contains a function (`trplot()`) that plots a single LD triangle as seen in Figure 5.
The Details of this script are explained below.
The output depends on the data set plotted (sub figure a contains additional annotations).

We create an empty list that is then filled with the subplots using the `trplot()` function.

```{r basePlot,results='hide',message=FALSE}
plts <- list()

for(k in 1:3){
plts[[k]] <- trplot((8:10)[k])
}
```

The basic plots are transformed into `grid obgects`.
These are afterwards rotated by 45 degrees.

```{r grobPlot,results='hide', message=FALSE, warning=FALSE}
tN <- theme(legend.position = 'none')

pG8 <- ggplotGrob(plts[[1]]+tN)
pG9 <- ggplotGrob(plts[[2]]+tN)
pG10 <- ggplotGrob(plts[[3]]+tN)
pGr8 <- editGrob(pG8, vp=viewport(x=0.5, y=0.97, angle=45,width = .76), name="pG8")
pGr9 <- editGrob(pG9, vp=viewport(x=0.5, y=0.62, angle=45,width = .7), name="pG9")
pGr10 <- editGrob(pG10, vp=viewport(x=0.5, y=0.3, angle=45,width = .7), name="pG10")
```

Then, external annotations loaded and the legend ins extracted from the first plot.

```{r annotatePlot,results='hide', message=FALSE, warning=FALSE}
npGrob <- gTree(children=gList(pictureGrob(readPicture("../../0_data/0_img/pue-nig-cairo.svg"))))
puGrob <- gTree(children=gList(pictureGrob(readPicture("../../0_data/0_img/uni-pue-cairo.svg"))))
nuGrob <- gTree(children=gList(pictureGrob(readPicture("../../0_data/0_img/nig-uni-cairo.svg"))))

leg <- get_legend(plts[[1]]+theme(legend.text = element_text(size = 5),
                                   legend.title =  element_text(size = 5),
                                   legend.key.size = unit(7,'pt')))
```

Finally, the complete Figure 5 is put together.

```{r finalPlot,results='hide', message=FALSE, warning=FALSE}
F5 <- ggdraw(pGr8)+
  draw_grob(pGr9,0,0,1,1)+
  draw_grob(leg,-.65,.04,1,1)+
  draw_grob(pGr10,0,0,1,1)+
  draw_grob(npGrob, 0.7, 0.7, 0.28, 0.1)+
  draw_grob(nuGrob, 0.7, 0.37, 0.28, 0.1)+
  draw_grob(puGrob, 0.7, .04, 0.28, 0.1)
```

The final figure is then exported using `ggsave()`.

```{r, eval=FALSE}
#ggsave(plot = F5,filename = '../output/F5.pdf',width =  91.5,height = 145,units = 'mm',device = cairo_pdf)
ggsave(plot = F5,filename = '../output/F5.png',width = 91.5,height = 145,units = 'mm',dpi = 150)
```

<center>
```{r f5SHOW, echo=FALSE, fig.height=145*0.03937008, fig.width=91.5*0.03937008, warning=FALSE}
F5
```
</center>
---