2

I am trying to create and save multiple plots with qgraph(). So far I tried:

for (i in 1:100){
    png(paste(i,".png",sep="_"))
    qgraph(l[[i]])
    dev.off()
}

l is a list of 100 weight matrices.

Creating a plot outside of the for loop works without problems.

The for loop also works with with plot(), instead of qgraph().

Alternatively I used:

qgraph.animate(l,progress=FALSE)

Using qgraph.animate() creates 100 plots. Is there a way of saving them? This would also have the benefit of being able to use constraint argument.

kdopen
  • 8,032
  • 7
  • 44
  • 52
M.Schuler
  • 33
  • 3
  • Maybe unrelated to your problem, but `paste(i,".png",sep="_")` returns strings like `"1_.png"`, is that what you were expecting? – mickey Dec 20 '18 at 17:04
  • Yeah, that's fine for now. I will change it into more meaningful names, once the loop is running. – M.Schuler Dec 21 '18 at 09:35

1 Answers1

1

I found a solution for my own question. It takes two steps to get there.

  1. Create and save list of plots:

    tert1_aggr_dates_coef_qgraph<-qgraph.animate(l,progress=F, constraint = .1)

  2. Use list of plots in for loop, to create and save plots.

    for(i in 1:100){

    jpeg(paste(i,".jpg"))

    qgraph(tert1_aggr_dates_coef_qgraph[[i]])

    dev.off()}

M.Schuler
  • 33
  • 3