Birds in space… (multidimensional trait-space)

movieAn animated rotation of a plot of cloud forest bird species in their multidimensional trait space, showing vectors of trait variables, and spiders linking groups defined from a separate clustering analysis.

A small success in R yesterday, I finally managed to generate a 3d movie of the arrangement of species in the multidimensional trait space I am currently working with, for cloud forest birds in the Colombian Andes.  The output above uses the “rgl” and “vegan” packages to produce a series of .png files that animate the plot rotation, and for the conversion to video requires “imagemagick” to be installed (which in turn requires Xcode and macports to get it all happening).  I found great help for getting my initial code just for 3d plots to work on stack overflow.

It is not executable, but below is what my code looks like.

# you will need a distance matrix called tdist…
# check the spread of points in an ordination
vare.mds0 = isoMDS(tdist, k = 10) # keep ten dimensions of the ordination

# fit some environmental variables
trait_fit3d = envfit(vare.mds0, traits3, choices = 1:3,arrow.mul = 10)
str(trait_fit3d)

# set the points of the ordination
vare.mds0$points=vare.mds0$points[order(rownames(vare.mds0$points)),]

# construct a plot using the rgl wrapper for vegan
pl = ordirgl(object = vare.mds0 , display = “sites”, type = “points”,
             choices = 1:3, ax.col = “green”,cex = .125,
             arr.col = “skyblue”, envfit = trait_fit3d)
# add some points
pl = pl + orglpoints(object = vare.mds0, display = “sites”, choices = 1:3, colour = “blue”)

# make a plot with spiders, and vectors
pl = pl+ orglspider(object = vare.mds0, groups = x$tgroups2 , display = “sites”,
                    choices = 1:3)

# set some device parameters
rgl.viewpoint(theta = 0, phi = 30, fov = 90, zoom = .55, scale = par3d(“scale”),
              interactive = TRUE )

#spin the plot
play3d(spin3d(axis=c(1,0,0), rpm=5), duration=10)

# write a gif movie of the rotation
movie3d(spin3d(axis=c(1,0,0), rpm=4), duration=30, convert = TRUE,
        top = TRUE, type = “gif”)

# on completion R should then tell you the path to find the resulting gif file, buried in your r temp output folder somewhere
# on the mac, copy and paste this into you finder “go to folder” dialogue to retrieve it

 

This entry was posted in communications, investigations and tagged , , , , , , , . Bookmark the permalink.

Leave a comment