/
ROI_data.Rmd
155 lines (135 loc) · 4.89 KB
/
ROI_data.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
---
title: "ROI_data"
author: "Tristan Caro"
date: "7/3/2021"
output: html_document
---
# Collecting ROI Data
ROI data has been collected into a folder `June_2021/roi_data`
```{r}
# Load Libraries
library(tidyverse)
library(readxl)
library(ggsci)
library(ggdist)
library(plotly)
```
```{r, echo=FALSE, message=FALSE}
temp_list = list.files(path = "June_2021/roi_data", pattern="*.tsv")
#roi_data = lapply(paste0("June_2021/roi_data/", temp), read_tsv)
# Create an empty tibble with pre-defined colnames
# I wish I knew a better way to create an empty tibble but this will have to do
tbl_colnames <- c("N_source", "light", "inc_time_hr", "ROI", "12C", "13C", "14N_12C", "15N_12C", "31P", "32S", "34S", "SE", "Ratio_15N_12Cx14N_12C" )
roi_tbl <- tibble(
)
roi_tbl <- roi_tbl[-1,] # Remove the garbage row of the tibble
# Read in each .tsv, append each to the roi_tbl we just generated
for (tsv in temp_list) {
tmp_df <- read_tsv(paste0("June_2021/roi_data/", tsv))
tmp_df <- tmp_df %>% mutate(filename = tsv)
roi_tbl <- bind_rows(roi_tbl, tmp_df)
}
```
```{r}
# Parse filenames to generate conditions
roi_tbl <- roi_tbl %>% mutate(
N_source = case_when(
str_detect(filename, regex('NH4', ignore_case = TRUE)) ~ "NH4",
str_detect(filename, regex('no3', ignore_case = TRUE)) ~ "no3",
str_detect(filename, regex('TMA', ignore_case = TRUE)) ~ "TMA",
str_detect(filename, regex('gly', ignore_case = TRUE)) ~ "gly",
str_detect(filename, regex('CN', ignore_case = TRUE)) ~ "CN",
str_detect(filename, regex('HPG', ignore_case = TRUE)) ~ "HPG"),
light = case_when(
str_detect(filename, "light") ~ "light",
str_detect(filename, "dark") ~ "dark"),
incubation_time_hr = 96,
cell_type = case_when(
Group == "red" ~ "Picocystis",
Group == "green" ~ "Picocystis triplet",
Group == "blue" ~ "Other"),
cell_type_other = case_when(
cell_type == "Picocystis" ~ "Picocystis",
cell_type == "Picocystis triplet" ~ "Picocystis",
cell_type == "Other" ~ "Other"
)
)
```
```{r}
# Write master .tsv file for posterity or other analyses
write_tsv(roi_tbl, "roi_tbl.tsv")
```
# Plot!
```{r}
p_roi_tbl_1 <- roi_tbl %>% ggplot(aes(x = N_source, y=Ratio_15N_12Cx14N_12C, color = cell_type)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position=position_jitterdodge(jitter.width = 0.1), size = 0.2) +
scale_color_aaas() +
facet_wrap(vars(light)) +
geom_hline(yintercept = .00364, color = "red") +
theme_classic()
ggsave(plot = p_roi_tbl_1, filename = "p_roi_tbl1.png")
p_roi_tbl_1
p_roi_tbl_1_dark <- roi_tbl %>%
filter(light == "dark") %>%
ggplot(aes(x = N_source, y = Ratio_15N_12Cx14N_12C, color = cell_type)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position=position_jitterdodge(jitter.width = 0.1), size = 0.2) +
scale_color_aaas() +
geom_hline(yintercept = .00364, color = "red") +
theme_classic() +
ggtitle("Dark Conditions") +
theme()
p_roi_tbl_1_dark
p_roi_tbl_1_no_nh4 <- roi_tbl %>%
filter(N_source != "NH4") %>%
ggplot(aes(x = N_source, y = Ratio_15N_12Cx14N_12C, color = cell_type)) +
geom_boxplot(outlier.shape = NA) +
geom_point(position=position_jitterdodge(jitter.width = 0.1), size = 0.2) +
scale_color_aaas() +
geom_hline(yintercept = .00364, color = "red") +
theme_classic() +
ggtitle("Dark Conditions") +
facet_wrap(vars(light)) +
theme_classic() +
ggtitle("No NH4")
p_roi_tbl_1_no_nh4
```
```{r}
# Raincloud plotting
p_NH4_active_raincloud <- roi_tbl %>% filter(N_source == "NH4", cell_type != "Other") %>%
ggplot(aes(x = Ratio_15N_12Cx14N_12C, fill = light)) +
stat_slab(alpha = 0.6, height = 0.5) +
geom_point(y = -.20, size = 10, shape = 124, alpha = 0.3) +
stat_pointinterval(y = 0, alpha = 0.5) +
facet_wrap(vars(light), ncol = 1, strip.position = "right") +
scale_fill_aaas() +
theme_classic() +
theme(legend.position = "none",
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank())
ggsave(p_NH4_active_raincloud, filename = "NH4_active_raincloud.png", height = 3, width = 7)
```
```{r}
# Calculate median µ and generation time to manually plot on top of this
roi_tbl %>% filter(N_source == "NH4") %>%
group_by(light) %>%
summarize(med_mu_d = median(mu_d),
med_gen_d = median(gen_d))
```
```{r}
p_NH4_active_raincloud <- roi_tbl %>% filter(N_source == "NH4", cell_type != "Other") %>%
ggplot(aes(x = Ratio_15N_12Cx14N_12C, fill = light)) +
stat_slab(alpha = 0.6, height = 0.5) +
geom_point(y = -.20, size = 10, shape = 124, alpha = 0.3) +
stat_pointinterval(y = 0, alpha = 0.5) +
facet_wrap(vars(light), ncol = 1, strip.position = "right") +
scale_fill_aaas() +
theme_classic() +
theme(legend.position = "none",
axis.title.y = element_blank(),
axis.ticks.y = element_blank(),
axis.text.y = element_blank())
ggsave(p_NH4_active_raincloud, filename = "NH4_active_raincloud.png", height = 3, width = 7)
```