Objective

Create a video of a given trait recorded in the phenoArch platform. This tutorial will use the imageGreenhouse() function and the animation R package.

https://cran.r-project.org/package=animation

SystemRequirements: ImageMagick (http://imagemagick.org) or GraphicsMagick (http://www.graphicsmagick.org) or LyX (http://www.lyx.org) for saveGIF(); (PDF)LaTeX for saveLatex(); SWF Tools (http://swftools.org) for saveSWF(); FFmpeg (http://ffmpeg.org) or avconv (https://libav.org/avconv.html) for saveVideo()

  #-- Loading of librairies
  library(tidyr)
  library(dplyr)
  library(phisStatR)
  library(animation)

Code for creating a video

  # import a temporal dataframe from phisStatR package:
  data(plant1)

  str(plant1)

  head(plant1)

  # Number of Days in the dataframe (in the experiment)
  table(plant1[,"Day"])

  plant1<-arrange(plant1,Day)

The code below is not evaluated but just presented. Indeed, to create a video, R must save each temporal graphic in a repertory and then create the video using all the files. We just here show how to do this. Please try it with your own path and folder hierarchy.

    #----------------------------------------------------
    #heat map biovolume per Day and creation of a gif video
    #----------------------------------------------------
    vecDay<-na.omit(unique(plant1[,"Day"]))

    videoFileName<-"biovolume"

    saveVideo({
      for (tmpday in 1:length(vecDay)){
        imageGreenhouse(datain=filter(plant1,Day==vecDay[tmpday]),trait="biovolume",typeD=1,typeT=1,ylim=NULL,
                        xcol="Line",ycol="Position",numrow=28,numcol=60,
                        typeI="video")
      } 
      ani.options(interval = 1,ani.dev="png",ani.height=480)
      },
      video.name = paste0(thepath,"/output/",videoFileName,".gif"), 
      other.opts = paste0("-y -r ",length(vecDay)+2," -i Rplot%d.png -dframes ",
                          length(vecDay)+2," -r ",length(vecDay)+2)
    )

  # Call the video in a Rmarkdown file
  #![](/my-path-to-project/output/humidity.gif)

Session info

  sessionInfo()

References

  1. R Development Core Team (2015). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. ISBN 3-900051-07-0, URL http://www.R-project.org.
  2. Yihui Xie (2013). animation: An R Package for Creating Animations and Demonstrating Statistical Methods. Journal of Statistical Software, 53(1), 1-27. URL http://www.jstatsoft.org/v53/i01/.


sanchezi/phisStatR documentation built on Nov. 14, 2019, 7:10 p.m.