-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3. SimulationPlot.Rmd
208 lines (156 loc) · 5.58 KB
/
3. SimulationPlot.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
---
title: "Simluation plot for age of ischemic stroke onset."
author: "[Sander W. van der Laan, PhD](https://swvanderlaan.github.io) | @swvanderlaan | [email protected]"
date: "`r Sys.Date()`"
output:
html_notebook:
cache: yes
code_folding: hide
collapse: yes
df_print: paged
fig.align: center
fig_caption: yes
fig_height: 6
fig_retina: 2
fig_width: 7
highlight: tango
theme: lumen
toc: yes
toc_float:
collapsed: no
smooth_scroll: yes
mainfont: Arial
subtitle: "A 'druggable-MI-targets' project"
editor_options:
chunk_output_type: inline
---
# General Setup
We will clean the environment, setup the locations, define colors, and create a datestamp.
_Clean the environment._
```{r echo = FALSE}
rm(list = ls())
```
_Set locations and working directories..._
```{r LocalSystem, echo = FALSE}
source("scripts/local.system.R")
```
_... a package-installation function ..._
```{r Function: installations}
source("scripts/functions.R")
```
_... and load those packages._
```{r loading_packages, message=FALSE, warning=FALSE}
source("scripts/packages.R")
```
_We will create a datestamp and define the Utrecht Science Park Colour Scheme_.
```{r Setting: Colors}
Today = format(as.Date(as.POSIXlt(Sys.time())), "%Y%m%d")
Today.Report = format(as.Date(as.POSIXlt(Sys.time())), "%A, %B %d, %Y")
source("scripts/colors.R")
```
```{r global_options, include = FALSE}
# further define some knitr-options.
knitr::opts_chunk$set(fig.width = 12, fig.height = 8, fig.path = 'Figures/',
wwarning = TRUE, # show warnings during codebook generation
message = TRUE, # show messages during codebook generation
error = TRUE, # do not interrupt codebook generation in case of errors,
# usually better for debugging
echo = TRUE, # show R code
eval = TRUE)
ggplot2::theme_set(ggplot2::theme_minimal())
pander::panderOptions("table.split.table", Inf)
```
# Introduction
We will parse the data to create regional association plots for each of the 11 loci.
# Setting the NPG colors
```{r}
library("scales")
pal_npg("nrc")(10)
show_col(pal_npg("nrc")(10))
# show_col(pal_npg("nrc", alpha = 0.6)(10))
```
# Load data
We need to load the data first. This was generated in SAS with `scripts/simulateCaseControl.sas`.
```{r}
simdataAAO <- fread(file = paste0(PROJECT_loc, "/simulation_data/simulation_data_AAO.csv"))
str(simdataAAO)
```
```{r}
simdataStrokeCC <- fread(file = paste0(PROJECT_loc, "/simulation_data/simulation_data_StrokeCC.csv"))
str(simdataStrokeCC)
```
```{r}
library(dplyr)
simdataAAO <- simdataAAO %>%
mutate(study = recode(study,
"Additive Effect on Stroke" = "Additive genetic effect",
"Multiplicative SNP Effect on Stroke" = "Multiplicative genetic effect",
"SNP Effect on Death" = "Genetic effect on death"))
simdataAAO$Design <- "age at onset"
simdataStrokeCC <- simdataStrokeCC %>%
mutate(study = recode(study,
"Additive SNP Effect on Stroke" = "Additive genetic effect",
"Multiplicative SNP Effect on Stroke" = "Multiplicative genetic effect",
"SNP Effect on Death" = "Genetic effect on death"))
simdataStrokeCC$Design <- "case-control"
```
```{r}
simdata <- rbind(simdataAAO, simdataStrokeCC)
# create Design `as.factor`
simdata$Design <- as.factor(simdata$Design)
levels(simdata$Design)
simdata$Design <- factor(simdata$Design, levels=c("case-control", "age at onset"))
simdata$study <- factor(simdata$study, levels=c("Additive genetic effect", "Multiplicative genetic effect", "Genetic effect on death"))
dim(simdata)
head(simdata)
str(simdata)
```
# Simulation plotting
```{r}
ggpubr::ggline(simdata,
x = "gEffect",
y = "PERCENT",
facet.by = "Design",
color = "study", palette = "npg",
plot_type = "l",
linetype = 1,
size = 1.25,
# shape = 19,
# stroke = 2,
point.size = 1.25,
# point.color = "npg",
xlab = "Genetic effect size", ylab = "Power",
ylim = c(0, 100),
legend = "right",
ggtheme = theme_minimal()) +
theme(axis.line = element_line(size = 1, colour = uithof_color[25]),
# legend.position = c(0, 1),
legend.justification = c("left", "top"),
legend.box.just = "left",
legend.margin = margin(6, 6, 6, 6)) +
labs(color = "Simulated genetic effect")
ggsave(paste0(PROJECT_loc, "/simulation_graph/SimulationResults.png"), plot = last_plot())
ggsave(paste0(PROJECT_loc, "/simulation_graph/SimulationResults.pdf"), plot = last_plot())
ggsave(paste0(PROJECT_loc, "/simulation_graph/SimulationResults.eps"), plot = last_plot())
```
# Session information
------
Version: v1.0.1
Last update: 2023-08-21
Written by: Sander W. van der Laan (s.w.vanderlaan-2[at]umcutrecht.nl).
Description: Script to create simulation plot.
Minimum requirements: R version 3.4.3 (2017-06-30) -- 'Single Candle', Mac OS X El Capitan
Changes log
* v1.0.1 Fixed genetic effects and power figure for clarity.
* v1.0.0 Initial version.
------
```{r eval = TRUE}
sessionInfo()
```
# Saving environment
```{r Saving}
save.image(paste0(PROJECT_loc, "/",Today,".",PROJECTNAME,".SimulationPlot.RData"))
```
------
<sup>© 1979-2022 Sander W. van der Laan | s.w.vanderlaan[at]gmail.com | [swvanderlaan.github.io](https://swvanderlaan.github.io).</sup>
------