arrange multiple graphs using a for loop in ggplot2

前端 未结 4 855
有刺的猬
有刺的猬 2021-02-04 19:37

I want to produce a pdf which shows multiple graphs, one for each NetworkTrackingPixelId. I have a data frame similar to this:

> head(data)
  Net         


        
4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 19:57

    I recently had a project that required producing a lot of individual pngs for each record. I found I got a huge speed up doing some pretty simple parallelization. I am not sure if this is more performant than the dplyr or data.table technique but it may be worth trying. I saw a huge speed bump:

    require(foreach)
    require(doParallel)
    workers <- makeCluster(4)
    registerDoParallel(workers) 
    foreach(i = seq(1, length(mtcars$gear)), .packages=c('ggplot2')) %dopar% {
      j <- qplot(wt, mpg, data = mtcars[i,])
      png(file=paste(getwd(), '/images/',mtcars[i, c('gear')],'.png', sep=''))
      print(j)
      dev.off()
    }
    

提交回复
热议问题