r - RScript - ggplot() 和 ggsave() 循环不遍历列表
问题描述
我正在尝试使用带有 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 中生成其余图。有没有人知道为什么其余的情节没有输出?
提前谢谢了!
解决方案
您正在将 temp 2 设为长度为 1 的列表。
temp2 = gsub("*.txt.out$", "", list.files(pattern="*.out"))
推荐阅读
- sql - 我们如何使用立即执行将完整的 sql 查询从表传递到 PL/SQL 中的插入语句
- python - 创建没有重复的字典
- php - SimpleXML 显示特定属性的值
- c - C 中带 void 和不带 void 的 main 函数
- javascript - Vue:加载静态脚本
- python - 导入错误:python for 3.7 但在 2.7 中没有错误
- wordpress - 在运输 woocommerce 中添加额外费用
- vb6 - VB6 redim 错误“此数组已修复或暂时锁定”
- javascript - 不使用 CSS 的 JavaScript 移动过渡
- swift - PDFKit 注释保存文本注释