Plot 3D Wireframes from Morphologika

February 25, 2013
By

(This article was first published on geomorph, and kindly contributed to R-bloggers)

Hi morphometricians,
A quick update: a function to plot Morphologika 3D wireframes using the package geomorph. This routine (or a version of it) will be included in our next package update under the “read.morphologika” function.

Enjoy!

Example:

library(geomorph)
# create an array of 10 random 3D specimens with 6 landmarks each to GPA
data<-array(abs(rnorm(18*10)),c(6,3,5))

# create a simple wireframe, e.g., pt1 connects to pt2, 2-to-3, 3-to-4,…etc.
wireframe<-matrix(c(1,2,2,3,3,4,4,5,5,6),ncol=2,byrow=T)
wireframe
mydata.gpa<-gpagen(data) #gpa landmarks

# choose the largest and/or smallest specimen
max<-which.max(mydata.gpa$Csize) #ID specimen w/largest CS
min<-which.min(mydata.gpa$Csize) #ID specimen w/smallest CS

# wireframe function: wirefun
# Input: 2 matrices: A & W
#  A is the procrustes residualsmatrix
#  W is the wireframe matrix
wirefun<-function(A,W,…){
  plot3d(A,type=”n”, aspect=FALSE,…)
  for(i in 1:dim(W)[1]){
    points3d(A[W[i,],],…)
    text3d(A[W[i,],],texts=W[i,],…)
    lines3d(rbind(A[W[i,1],],A[W[i,2],]),…)
  }
}

# Plot
wirefun(A=mydata.gpa$coords[,,1],W=wireframe,size=10,adj=2.5,col=”black”)

To leave a comment for the author, please follow the link and comment on their blog: geomorph.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

Mango solutions



RStudio homepage



Zero Inflated Models and Generalized Linear Mixed Models with R

Quantide: statistical consulting and training



http://www.eoda.de









ODSC

CRC R books series











Contact us if you wish to help support R-bloggers, and place your banner here.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)