[R-sig-eco] Length frequency figures
Sarah Goslee
sarah.goslee at gmail.com
Sat Jul 16 16:10:04 CEST 2011
David,
For the latter example, you can use xlim=c(min, max) to set the range
of the x axis. R graphics are infinitely customizable, but the
settings are cryptic. Carefully reading ?par may help.
Sarah
On Fri, Jul 15, 2011 at 4:09 PM, David Bryan <dbryan at rsmas.miami.edu> wrote:
> 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
>
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-sig-ecology
mailing list