[英]RScript - ggplot() and ggsave() loop not iterating through list
我正在嘗試使用帶有 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")
}
該代碼成功地從列表中的第一個數據幀輸出了第一個 plot,但循環似乎沒有遍歷列表並在 ggsave 中生成圖的 rest。 有沒有人對為什么不輸出繪圖的 rest 有任何見解?
提前謝謝了!
您正在將 temp 2 設為長度為 1 的列表。
temp2 = gsub("*.txt.out$", "", list.files(pattern="*.out"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.