Update to curves2d()

June 20, 2013
By

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


Dear morphometricians,

Below you will find an update to our function for digitizing curves in 2d: curves2d(). This solves a problem with the function plotting landmarks and semilandmarks out of sequence. To use it, you can "source()" the code from a directory, or copy and paste it during digitizing.


Cheers,

Erik

CODE:

curves2d<-function(file, nsliders){
lm<-readland.nts(spec.name<-basename(file))
lm <- matrix(lm, ncol = dim(lm)[2], byrow=T)
spec.name<-unlist(strsplit(spec.name, "\\."))[1]
plot(lm[,1],lm[,2],cex=1,pch=21,bg="white")
text(lm[,1],lm[,2],label=paste("LM",1:dim(lm)[1]),adj=.5,pos=1)
selected<-matrix(NA,ncol=3,nrow=nsliders)
select<-NULL
for(i in 1:nsliders){
for(j in 1:3){
select<-identify(lm,n=1,plot=FALSE,cex=5,pch=25)
selected[i,j]<-select
if(j==2){
points(lm[select,][1],lm[select,][2],cex=1.5,pch=19,col="red")
arrows(lm[selected[i,j],][1],lm[selected[i,j],][2],lm[selected[i,j-1],][1],lm[selected[i,j-1],][2]
,col="red",lwd=2,length=.15)
} else {
points(lm[select,][1],lm[select,][2],cex=1.1,pch=19,col="blue")
}
if(j==3){
arrows(lm[selected[i,j],][1],lm[selected[i,j],][2],lm[selected[i,j-1],][1],lm[selected[i,j-1],][2]
,col="red",lwd=2,length=.15,code=1)
#lines(rbind(lm[selected[i,j],],lm[selected[i,j-1],]),col="red",lwd=2)
} else { NA
}
}
}
output<-selected
cat(paste(‘"sliders’,sep=""),file=paste("sliders.nts",sep=""),sep="\n")
cat(paste(1,dim(output)[1],3,0, "dim=3"),file="sliders.nts",sep="\n",append=TRUE)
write.table(output,file="sliders.nts",col.names = FALSE, row.names = FALSE,sep=" ",append=TRUE)
return(list(sliders=output))
}

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)