-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid_ap_figures.Rmd
82 lines (57 loc) · 5.48 KB
/
covid_ap_figures.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
---
title: "Codes for making figures for Archive of Pathology Paper"
output: html_document
author: "Run Jin"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R codes to generate figure
# Note that the code does not include the data read in files - the files are stored in local directories. Therefore, this file would not be able to display in knitr.
```{r setup}
install.packages(tidyverse)
library(tidyverse)
```
Read in the excel file and gathre information of target 1 and target 2 Ct values:
```{r}
NxTAG_lowP_gather <- NxTAG_lowP %>% gather(target_id, ct_values, c(Target1_Ct, Target2_Ct))
NxTAG_cons_gather <- NxTAG_cons %>% gather(target_id, ct_values, c(Target1_Ct, Target2_Ct))
abbott_lowP_gather <- abbott_lowP %>% gather(target_id, ct_values, c(Target1_Ct, Target2_Ct))
abbott_cons_gather <- abbott_cons %>% gather(target_id, ct_values, c(Target1_Ct, Target2_Ct))
```
Factors are re-leveled to put "positive" first. New categories are added to mark those files for later combination:
```{r}
NxTAG_lowP_gather$NxTAG_results <- factor(NxTAG_lowP_gather$NxTAG_results, levels = c("Positive", "Negative"))
NxTAG_cons_gather$NxTAG_results <- factor(NxTAG_cons_gather$NxTAG_results, levels = c("Positive", "Negative"))
abbott_lowP_gather$Abbott_results <- factor(abbott_lowP_gather$Abbott_results, levels = c("Positive", "Negative"))
abbott_cons_gather$Abbott_results <- factor(abbott_cons_gather$Abbott_results, levels = c("Positive", "Negative"))
NxTAG_lowP_gather <- NxTAG_lowP_gather %>% mutate(category = "lowP")
NxTAG_cons_gather <- NxTAG_cons_gather %>% mutate(category = "Cons")
abbott_cons_gather <- abbott_cons_gather %>% mutate(category = "Cons")
abbott_lowP_gather <- abbott_lowP_gather %>% mutate(category = "lowP")
```
Generate plots.
```{r}
ggplot(NxTAG_lowP_gather, aes(x = NxTAG_results, y = ct_values, color = NxTAG_results)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15,40) + scale_fill_manual(values=c("red", "blue")) +scale_color_manual(values=c("red", "blue")) + theme_bw()
ggplot(NxTAG_cons_gather, aes(x = NxTAG_results, y = ct_values, color = NxTAG_results)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15,40) + scale_fill_manual(values=c("red", "blue")) +scale_color_manual(values=c("red", "blue")) + theme_bw()
ggplot(abbott_cons_gather, aes(x = Abbott_results, y = ct_values, color = Abbott_results)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15,40) + scale_fill_manual(values=c("red", "blue")) +scale_color_manual(values=c("red", "blue")) + theme_bw()
ggplot(abbott_lowP_gather, aes(x = Abbott_results, y = ct_values, color = Abbott_results)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15,40) + scale_fill_manual(values=c("red", "blue")) +scale_color_manual(values=c("red", "blue")) + theme_bw()
```
Different datasets with the same testing methods are combined to generate a combined figure.
```{r}
NxTAG_all_gather <- bind_rows(NxTAG_lowP_gather, NxTAG_cons_gather)
NxTAG_all_gather$full_cat <-paste(NxTAG_all_gather$NxTAG_results, NxTAG_all_gather$category, sep = "_")
abbott_all_gather <- bind_rows(abbott_lowP_gather, abbott_cons_gather)
abbott_all_gather$full_cat <-paste(abbott_all_gather$Abbott_results, abbott_all_gather$category, sep = "_")
ggplot(abbott_all_gather, aes(x = Abbott_results, y = ct_values, color = full_cat)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15, 40) + scale_fill_manual(values=c("red", "#037f51", "blue", "purple")) +scale_color_manual(values=c("red", "#037f51", "blue", "purple")) + theme_bw()
ggplot(NxTAG_all_gather, aes(x = NxTAG_results, y = ct_values, color = full_cat)) + geom_boxplot() + geom_jitter(shape = 16, size = 2, position = position_jitter(0.2)) + facet_grid( . ~ target_id) + ylim(15, 40) + scale_fill_manual(values=c("red", "#037f51", "blue", "purple")) +scale_color_manual(values=c("red", "#037f51", "blue", "purple")) + theme_bw()
```
Generate graphs for all the tested specimens by Jefferson, faceted by target 1 or 2 and makes a histogram:
```{r}
all_tested$count <- 1:nrow(all_tested)
all_tested_gather <- all_tested %>% gather(target_id, ct_values, c(Target1_Ct, Target2_Ct))
ggplot(all_tested_gather, aes(x = count, y = ct_values, color = target_id)) + geom_point() +scale_color_manual(values=c("red", "blue")) + theme_bw()
ggplot(all_tested, aes(x = Target1_Ct, y = Target2_Ct)) + ylim(10, 50) + xlim(10, 50) + geom_point() + geom_rug() + theme_bw()
ggplot(all_tested_gather, aes(x = ct_values, color = target_id)) + geom_histogram() + theme_bw() + facet_grid(target_id ~ .) + xlim(11, 49) + scale_fill_manual(values=c("grey", "orange")) +scale_color_manual(values=c("grey", "orange"))
ggplot(all_tested_gather, aes(x = ct_values, color = target_id, fill = target_id)) + geom_histogram(binwidth = 1, center= 0.5) + theme_bw() + facet_grid(target_id ~ .) + scale_fill_manual(values=c("#999999", "#FFCC66")) + scale_color_manual(values=c("#333333", "#FF6600")) + stat_bin(geom = "text", aes(label = stat(count)), binwidth = 1, center = 0.5, vjust = -1) + ylim(0, 130) + geom_vline(xintercept = 26.16, colour = "#999999", linetype = "dashed") + geom_vline(xintercept = 26.52, colour = "#FF6600", linetype = "dashed") + geom_vline(xintercept = 35, colour = 'black')
```