[R-sig-eco] Length frequency figures

David Bryan dbryan at rsmas.miami.edu
Fri Jul 15 22:09:56 CEST 2011


I would like to create two histograms or two barplots to compare length 
frequency data between two different sampling methods. I am struggling 
with two approaches.
num<-rnorm(100,30,10)
len<-round(num,0)
abund<-sample(1:10, replace=T, 100)
meth<-gl(2,50,100)
eg<-data.frame(meth,len,abund)

Approach 1:
require(lattice)
histogram(abund ~ len | factor(meth), type="count", data=eg)

Problem: I end up with plots of counts that treat an abundance value of 
5 the same as 1.

Approach 2:
eg1<-eg[which(eg$meth=="1"),]
eg2<-eg[which(eg$meth=="2"),]
require(sqldf)
meth1<-sqldf("SELECT len, sum(abund)AS SUMLENG FROM eg1 GROUP BY len")
meth2<-sqldf("SELECT len, sum(abund)AS SUMLENG FROM eg2 GROUP BY len")
par(mfrow=c(1,2))
barplot(meth1$SUMLENG,names.arg=meth1$len)
barplot(meth2$SUMLENG, names.arg=meth2$len)

Problem: With this approach I end up with different ranges of x axis 
values which make it hard to compare figures.

I would like to have two figures with the same x axis that show the sum 
of abundances over individual lengths.

Thanks for any help,

David



More information about the R-sig-ecology mailing list