[英]How to save multiple plots in R through looping?
I am using the following script to generate a network diagram.我正在使用以下脚本来生成网络图。 Since the script generates 300+ network diagrams and I need to save them in TIFF (.tiff) format.由于脚本生成了 300 多个网络图,我需要将它们保存为 TIFF (.tiff) 格式。 Can anyone help me with a looping command the simultaneously exports every plot.任何人都可以通过循环命令帮助我同时导出每个 plot。
address = vector()
net_density = vector()
net_diameter = vector()
ln= 0 #ln is short for line number
#contruct Relationship Tree
for (i in unique_reddit)
{ graph = construct_graph(reddit_content(i))
ln = ln + 1
address[ln] = i
net_density[ln] = edge_density(graph)
net_diameter[ln] = diameter(graph)
}
net_properties = data.frame(address, net_density, net_diameter)
You can save plot with the following code.您可以使用以下代码保存 plot。 The names are changed with a paste in the loop.名称通过循环中的粘贴进行更改。
Note that I can't test your code because I miss unique_reddit
variable.请注意,我无法测试您的代码,因为我错过了unique_reddit
变量。
address = vector()
net_density = vector()
net_diameter = vector()
ln= 0 #ln is short for line number
#contruct Relationship Tree
for (i in unique_reddit)
{
# create file
tiff(paste0("absolute_path/",i,".tiff") )
graph = construct_graph(reddit_content(i))
ln = ln + 1
address[ln] = i
net_density[ln] = edge_density(graph)
net_diameter[ln] = diameter(graph)
# Close the pdf file
dev.off()
}
net_properties = data.frame(address, net_density, net_diameter)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.