本文介绍了按照名称保存图表列表()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 假设我有一个我创建的地块列表。 library(ggplot2) plot< - list() plot $ a< - ggplot (汽车,aes(速度,dist))+ geom_point()图$ b 图$ c 现在,我想保存所有这些,用各自的名称(图)元素标注每个元素。 lapply(图,函数(x){ ggsave(文件名=粘贴(... ,.jpeg,sep =),plot = x) dev.off()} ) 我会用什么替换...,以便在我的工作目录中将地块保存为: a.jpeg b.jpeg c.jpeg lapply(名称(地块),函数(x)ggsave(文件名= paste(x,。jpeg,sep =),plot = plots [[x]])) Let's say I have a list of plots that I've created. library(ggplot2)plots <- list()plots$a <- ggplot(cars, aes(speed, dist)) + geom_point()plots$b <- ggplot(cars, aes(speed)) + geom_histogram()plots$c <- ggplot(cars, aes(dist)) + geom_histogram()Now, I would like to save all of these, labelling each with their respective names(plots) element. lapply(plots, function(x) { ggsave(filename=paste(...,".jpeg",sep=""), plot=x) dev.off() } )What would I replace "..." with such that in my working directory the plots were saved as: a.jpegb.jpegc.jpeg 解决方案 probably you need to pass the names of list:lapply(names(plots), function(x)ggsave(filename=paste(x,".jpeg",sep=""), plot=plots[[x]])) 这篇关于按照名称保存图表列表()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 03:04