我正在尝试使用一个带有ggplot()和ggsave()的循环,通过下面的代码从一组独立的数据框中创建一组图:
temp2 = list(gsub("*.txt.out$", "", list.files(pattern="*.out")))
for (i in 1:length(temp2)) {
Eg_cluster = temp2[[i]]
df = data.frame(eval(parse(text = Eg_cluster)))
myplot = ggplot(df, aes(xmin = start, xmax = end, y = molecule, fill = gene)) +
geom_gene_arrow() +
facet_wrap(~ molecule, scales = "free", ncol = 3) +
scale_fill_brewer(palette = "Set3") +
theme_genes() + ggtitle("snoRNA Cluster ", Eg_cluster)
ggsave(file = print(paste0(Eg_cluster, ".pdf")), plot = myplot, device = "pdf")
}代码成功地从列表中的第一个数据帧输出第一个图,但是循环似乎不会遍历列表并在ggsave中生成其余的图。有没有人知道为什么其余的图不能输出?
首先要感谢大家!
发布于 2021-04-15 03:23:30
您正在将temp 2设置为长度为1的列表。
temp2 = gsub("*.txt.out$", "", list.files(pattern="*.out"))https://stackoverflow.com/questions/67097806
复制相似问题