Если у вас есть символьный вектор myfiles
путей к файлам и один myplots
с путем к графикам, которые вы хотите сохранить, вы можете l oop через это:
myfiles <- c('file1.csv', 'file2.csv', 'file3.csv')
myplots <- c('plot1.png', 'plot2.png', 'plot3.png')
for(i in 1:length(myfiles)) {
data <- read_delim(myfiles[i],
";",
escape_double = FALSE,
trim_ws = TRUE) %>% melt()
TM_df_up <- data %>%
filter(value>0) %>% #filtering for upregulated genes
group_by(variable) %>%
count() %>% #summarises to give the number of DEGs per comparison
as.data.frame() %>%
mutate(direction="up")
TM_df_down <- data %>%
filter(value<0) %>% #filtering for downregulated genes
group_by(variable) %>%
count() %>%
as.data.frame() %>%
mutate(n=n*-1,direction="down")
TM_df_plot <- rbind(TM_df_up, TM_df_down)
ggplot(TM_df_plot, (aes(x=variable, y=n,
fill=direction, #up or down regulated
label=abs(n))))+ #label of number of DEGs as an absolute value
geom_bar(stat="identity", aes(alpha=0.1))+
geom_text(size = 6)+
labs(y=NULL,x=NULL)+
scale_x_discrete(labels= c("18 vs 20", #adding manual labels
"20 vs 22",
"22 vs 24",
"24 vs DS"))+
labs(
x = "Days after pollentation",
title = "TM_abi3-12 dog1-4cyp707a2"
)+
scale_fill_manual(values = c("blue", "red"))+ #changing the fill colours
scale_y_continuous(breaks=seq(-2900, 16500, 550))+ #changing the scale breaks
theme_minimal()+
theme(
plot.title = element_text(hjust = 0.5),
text = element_text(size=24),
panel.grid = element_blank(),
axis.text.x = element_text(angle=90, vjust=0.35, hjust = 3),
legend.position = "none"
)
ggsave(myplots[i], width=10, height=27, dpi=300)
}