visNetAnimate
is supposed to animate the same graph but with
multiple colorings according to input data matrix. The output can be a
pdf file containing a list of frames/images, a mp4 video file or a gif
file. To support video output file, the software 'ffmpeg' must be first
installed (also put its path into the system PATH variable; see Note).
To support gif output file, the software 'ImageMagick' must be first
installed (also put its path into the system PATH variable; see Note).
visNetAnimate(g, data, filename = "visNetAnimate", filetype = c("pdf", "mp4", "gif"), image.type = c("jpg", "png"), num.frame = ncol(data), sec_per_frame = 1, height.device = 7, margin = rep(0.1, 4), border.color = "#EEEEEE", colormap = c("bwr", "jet", "gbr", "wyr", "br", "yr", "rainbow", "wb"), ncolors = 40, zlim = NULL, colorbar = T, colorbar.fraction = 0.25, glayout = layout.fruchterman.reingold, glayout.dynamics = F, mtext.side = 3, mtext.adj = 0, mtext.cex = 1, mtext.font = 2, mtext.col = "black", ...)
If specifying the output file name (see argument 'filename' above), the output file is either 'filename.pdf' or 'filename.mp4' or 'filename.gif' in the current working directory. If no output file name specified, by default the output file is either 'visNetAnimate.pdf' or 'visNetAnimate.mp4' or 'visNetAnimate.gif'
When producing mp4 video, this function requires the installation of the software 'ffmpeg' at https://www.ffmpeg.org. Shell command lines for ffmpeg installation in Terminal (for both Linux and Mac) are:
wget -O ffmpeg.tar.gz
http://www.ffmpeg.org/releases/ffmpeg-2.7.1.tar.gz
mkdir ~/ffmpeg | tar xvfz ffmpeg.tar.gz -C ~/ffmpeg
--strip-components=1
cd ffmpeg
./configure --disable-yasm
./configure --disable-yasm --prefix=$HOME/ffmpeg
make
make install
export PATH=$HOME/ffmpeg:$PATH
ffmpeg -h
When producing gif file, this function requires the installation of the software 'ImageMagick' at http://www.imagemagick.org. Shell command lines for ImageMagick installation in Terminal are:
wget
http://www.imagemagick.org/download/ImageMagick.tar.gz
mkdir ~/ImageMagick | tar xvzf ImageMagick.tar.gz -C
~/ImageMagick --strip-components=1
cd ImageMagick
./configure --prefix=$HOME/ImageMagick
make
make install
export MAGICK_HOME=$HOME/ImageMagick
export PATH=$MAGICK_HOME/bin:$PATH
export
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$MAGICK_HOME/lib
For Mac: export MAGICK_HOME=$HOME/ImageMagick
export PATH=$MAGICK_HOME/bin:$PATH
export
DYLD_LIBRARY_PATH=$MAGICK_HOME/lib/
convert -list configure
identify -list
format
libjpeg
and
libpng
are installed. If NOT, for Mac try this: brew
install libjpeg libpng
To check whether ImageMagick does work,
please get additional information from: identify -list format
convert -list configure
On details, please refer to
http://www.imagemagick.org/script/advanced-unix-installation.php
# 1) generate a random graph according to the ER model g <- erdos.renyi.game(100, 1/100) # 2) produce the induced subgraph only based on the nodes in query subg <- dNetInduce(g, V(g), knn=0) # 3) visualise the module with vertices being color-coded by scores nnodes <- vcount(subg) nsamples <- 10 data <- matrix(runif(nnodes*nsamples), nrow=nnodes, ncol=nsamples) rownames(data) <- V(subg)$name # output as a pdf file visNetAnimate(g=subg, data=data, filetype="pdf")Congratulations! A file 'visNetAnimate.pdf' (in the directory /Users/hfang/Sites/SUPERFAMILY/dnet) has been created!# output as a mp4 file but with dynamic layout visNetAnimate(g=subg, data=data, filetype="mp4", glayout.dynamics=TRUE)Executing this command: 'ffmpeg -y -v quiet -r 1 -i /var/folders/wq/4cmk3m511571471lj67cpmbh0000gn/T//RtmpncsM2C/Rplot%06d.jpg -q:v 1 /var/folders/wq/4cmk3m511571471lj67cpmbh0000gn/T//RtmpncsM2C/visNetAnimate.mp4' Congratulations! A file 'visNetAnimate.mp4' (in the directory /Users/hfang/Sites/SUPERFAMILY/dnet) has been created!# output as a gif file but with dynamic layout visNetAnimate(g=subg, data=data, filetype="gif", glayout.dynamics=TRUE)Executing this command: 'convert -delay 100 /var/folders/wq/4cmk3m511571471lj67cpmbh0000gn/T//RtmpncsM2C/Rplot*.jpg /var/folders/wq/4cmk3m511571471lj67cpmbh0000gn/T//RtmpncsM2C/visNetAnimate.gif' Congratulations! A file 'visNetAnimate.gif' (in the directory /Users/hfang/Sites/SUPERFAMILY/dnet) has been created!