主要是学习如何循环处理,至于画什么图替换成自己的代码即可
rm(list = ls())
library(dplyr)
library(ggplot2)
folder_path <- "D:/result"
file_pattern <- "*.tsv"
temp <- list.files(path = folder_path, pattern = file_pattern)
temp
c <- dir()
for (i in 1:length(temp)) {
print(percent(i / length(temp)))
file <- read.table(temp[i], header = TRUE, sep = "\t")
b <- abs(file$Value)
a <- data.frame(Name = file$Name, Value = b)
name <- gsub(".tsv", "", c)[i]
plot <- a %>%
arrange(Value) %>%
mutate(Name = factor(Name, levels = Name)) %>%
ggplot(aes(x = Name, y = Value)) +
geom_bar(aes(fill = Value), stat = "identity", alpha = 0.6, width = 0.4) +
coord_flip() +
xlab("") +
theme_bw() +
theme(axis.text = element_text(size = 12, face = "bold"))
ggsave(file = paste0(name, ".png"), plot, width = 10, height = 10, units = "in", dpi = 600)
}