-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop_ggplot.Rmd
More file actions
60 lines (49 loc) · 1.82 KB
/
Copy pathloop_ggplot.Rmd
File metadata and controls
60 lines (49 loc) · 1.82 KB
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
---
title: "loop_ggplot"
author: "Suet Li Hooi"
date: "`r Sys.Date()`"
output: html_document
---
```{r}
setwd("~/AMILI_2022/DOLE")
library(tidyverse)
library(ggplot2)
library(phyloseq)
library(splitstackshape)
library(reshape2)
library(ggsignif)
library(gridExtra)
library(ggsci)
```
```{r}
#input for the below plots
psmelt_dole_raw <- read.csv('psmelt_dole_raw.csv')
```
```{r, fig.width=12, fig.height=10}
library(ggplot2)
# Create a function that takes filtering parameters as input and generates the plot
generate_plot <- function(data, filter_param, species_filter) {
filtered_data <- data %>%
filter(Group %in% filter_param,
grepl(species_filter, Species)) %>%
mutate(Abundance_log = log2(value))
ggplot(filtered_data, aes(Timepoint, value, fill = Timepoint)) +
scale_fill_manual(values = c("T0" = "grey", "T1" = "lightpink", "T2" = "lightblue")) +
geom_bar(stat = "identity") +
theme_bw() +
facet_wrap(vars(Subject.ID), ncol = 3, scales = "free_y") +
ylab("Relative abundance") + xlab("Intervention") +
ggtitle(paste("Relative abundance of", species_filter, "for", filter_param)) +
theme(text = element_text(size = 18))
}
# List of different filtering parameters and species filters
filter_params <- c("Green_Banana", "Pineapple", "Control")
species_filters <- c("Bifidobacterium_catenulatum", "Alistipes_onderdonkii", "Eubacterium_rectale", "Holdemanella_biformis", "Mitsuokella_multacida", "Bacteroides_caccae", "Coprococcus_comes","Phascolarctobacterium_succinatutens")
# Create and display plots for each combination of filtering parameters and species filters
for (param in filter_params) {
for (species_filter in species_filters) {
plot <- generate_plot(psmelt_dole_raw, param, species_filter)
print(plot)
}
}
```