1

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. Can anyone help me with a looping command the simultaneously exports every 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)
Phil
  • 7,287
  • 3
  • 36
  • 66
Johns Inos
  • 27
  • 5
  • Hi, your example is not complete as we miss `unique_reddit` variable. Please read https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Gowachin Apr 19 '21 at 21:10

1 Answers1

0

You can save plot with the following code. The names are changed with a paste in the loop.

Note that I can't test your code because I miss unique_reddit variable.

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)
Gowachin
  • 1,251
  • 2
  • 9
  • 17