Wednesday, October 15, 2014

10 15 2014 Size Class Code

sizeclassdata.R
require(TeachingDemos)
## Loading required package: TeachingDemos
require(ggplot2)
## Loading required package: ggplot2
require(scales)
## Loading required package: scales
require(plyr)
## Loading required package: plyr
nsize10<-sum(endfid$Tray_1=="2N"&10 %<=% endfid$Length.mm %<% 15)
nsize15<-sum(endfid$Tray_1=="2N"&15 %<=% endfid$Length.mm %<% 20)
nsize20<-sum(endfid$Tray_1=="2N"&20 %<=% endfid$Length.mm %<% 25)
nsize25<-sum(endfid$Tray_1=="2N"&25 %<=% endfid$Length.mm %<% 30)
nsize30<-sum(endfid$Tray_1=="2N"&30 %<=% endfid$Length.mm %<% 35)
nsize35<-sum(endfid$Tray_1=="2N"&35 %<=% endfid$Length.mm %<% 40)
nsize40<-sum(endfid$Tray_1=="2N"&40 %<=% endfid$Length.mm %<% 45)
nsize45<-sum(endfid$Tray_1=="2N"&45 %<=% endfid$Length.mm %<% 50)
nsize50<-sum(endfid$Tray_1=="2N"&50 %<=% endfid$Length.mm %<% 55)
nsize55<-sum(endfid$Tray_1=="2N"&55 %<=% endfid$Length.mm %<% 60)
sizeclassfidn<-matrix(c(nsize10,nsize15,nsize20,nsize25,nsize30,nsize35,nsize40,nsize45,nsize50,nsize55),ncol=10,byrow=F)
colnames(sizeclassfidn)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassfidn)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      8     34    102    129     83     22      1      0      0      0
hsize10<-sum(endfid$Tray_1=="2H"&10 %<=% endfid$Length.mm %<% 15)
hsize15<-sum(endfid$Tray_1=="2H"&15 %<=% endfid$Length.mm %<% 20)
hsize20<-sum(endfid$Tray_1=="2H"&20 %<=% endfid$Length.mm %<% 25)
hsize25<-sum(endfid$Tray_1=="2H"&25 %<=% endfid$Length.mm %<% 30)
hsize30<-sum(endfid$Tray_1=="2H"&30 %<=% endfid$Length.mm %<% 35)
hsize35<-sum(endfid$Tray_1=="2H"&35 %<=% endfid$Length.mm %<% 40)
hsize40<-sum(endfid$Tray_1=="2H"&40 %<=% endfid$Length.mm %<% 45)
hsize45<-sum(endfid$Tray_1=="2H"&45 %<=% endfid$Length.mm %<% 50)
hsize50<-sum(endfid$Tray_1=="2H"&50 %<=% endfid$Length.mm %<% 55)
hsize55<-sum(endfid$Tray_1=="2H"&55 %<=% endfid$Length.mm %<% 60)
sizeclassfidh<-matrix(c(hsize10,hsize15,hsize20,hsize25,hsize30,hsize35,hsize40,hsize45,hsize50,hsize55),ncol=10,byrow=F)
colnames(sizeclassfidh)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassfidh)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      6     68    117     97     20      6      0      0      0      0
ssize10<-sum(endfid$Tray_1=="2S"&10 %<=% endfid$Length.mm %<% 15)
ssize15<-sum(endfid$Tray_1=="2S"&15 %<=% endfid$Length.mm %<% 20)
ssize20<-sum(endfid$Tray_1=="2S"&20 %<=% endfid$Length.mm %<% 25)
ssize25<-sum(endfid$Tray_1=="2S"&25 %<=% endfid$Length.mm %<% 30)
ssize30<-sum(endfid$Tray_1=="2S"&30 %<=% endfid$Length.mm %<% 35)
ssize35<-sum(endfid$Tray_1=="2S"&35 %<=% endfid$Length.mm %<% 40)
ssize40<-sum(endfid$Tray_1=="2S"&40 %<=% endfid$Length.mm %<% 45)
ssize45<-sum(endfid$Tray_1=="2S"&45 %<=% endfid$Length.mm %<% 50)
ssize50<-sum(endfid$Tray_1=="2S"&50 %<=% endfid$Length.mm %<% 55)
ssize55<-sum(endfid$Tray_1=="2S"&55 %<=% endfid$Length.mm %<% 60)
sizeclassfids<-matrix(c(ssize10,ssize15,ssize20,ssize25,ssize30,ssize35,ssize40,ssize45,ssize50,ssize55),ncol=10,byrow=F)
colnames(sizeclassfids)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassfids)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      1     14     88    144     98     20      3      0      0      0
sizeclassfid<-rbind(sizeclassfidn,sizeclassfidh,sizeclassfids)
rownames(sizeclassfid)<-c("Fidalgo","Dabob","OysterBay")
broodersizes<-read.csv('Broodersizes.csv')
broodersizes$Date<-as.Date(broodersizes$Date,"%m/%d/%Y")
bnsize10<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&10 %<=% broodersizes$Size %<% 15)
bnsize15<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&15 %<=% broodersizes$Size %<% 20)
bnsize20<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&20 %<=% broodersizes$Size %<% 25)
bnsize25<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&25 %<=% broodersizes$Size %<% 30)
bnsize30<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&30 %<=% broodersizes$Size %<% 35)
bnsize35<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&35 %<=% broodersizes$Size %<% 40)
bnsize40<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&40 %<=% broodersizes$Size %<% 45)
bnsize45<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&45 %<=% broodersizes$Size %<% 50)
bnsize50<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&50 %<=% broodersizes$Size %<% 55)
bnsize55<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="N"&55 %<=% broodersizes$Size %<% 60)
sizeclassbrfidn<-matrix(c(bnsize10,bnsize15,bnsize20,bnsize25,bnsize30,bnsize35,bnsize40,bnsize45,bnsize50,bnsize55),ncol=10,byrow=F)
colnames(sizeclassbrfidn)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassbrfidn)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      0      1      0      2      4      1      0      0      0      0
bhsize10<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&10 %<=% broodersizes$Size %<% 15)
bhsize15<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&15 %<=% broodersizes$Size %<% 20)
bhsize20<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&20 %<=% broodersizes$Size %<% 25)
bhsize25<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&25 %<=% broodersizes$Size %<% 30)
bhsize30<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&30 %<=% broodersizes$Size %<% 35)
bhsize35<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&35 %<=% broodersizes$Size %<% 40)
bhsize40<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&40 %<=% broodersizes$Size %<% 45)
bhsize45<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&45 %<=% broodersizes$Size %<% 50)
bhsize50<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&50 %<=% broodersizes$Size %<% 55)
bhsize55<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="H"&55 %<=% broodersizes$Size %<% 60)
sizeclassbrfidh<-matrix(c(bhsize10,bhsize15,bhsize20,bhsize25,bhsize30,bhsize35,bhsize40,bhsize45,bhsize50,bhsize55),ncol=10,byrow=F)
colnames(sizeclassbrfidh)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassbrfidh)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      0      1      5      1      1      0      0      0      0      0
bssize10<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&10 %<=% broodersizes$Size %<% 15)
bssize15<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&15 %<=% broodersizes$Size %<% 20)
bssize20<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&20 %<=% broodersizes$Size %<% 25)
bssize25<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&25 %<=% broodersizes$Size %<% 30)
bssize30<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&30 %<=% broodersizes$Size %<% 35)
bssize35<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&35 %<=% broodersizes$Size %<% 40)
bssize40<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&40 %<=% broodersizes$Size %<% 45)
bssize45<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&45 %<=% broodersizes$Size %<% 50)
bssize50<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&50 %<=% broodersizes$Size %<% 55)
bssize55<-sum(broodersizes$Site=="Fidalgo"&broodersizes$Population=="S"&55 %<=% broodersizes$Size %<% 60)
sizeclassbrfids<-matrix(c(bssize10,bssize15,bssize20,bssize25,bssize30,bssize35,bssize40,bssize45,bssize50,bssize55),ncol=10,byrow=F)
colnames(sizeclassbrfids)<-c("S10-15","S15-20","S20-25","S25-30","S30-35","S35-40","S40-45","S45-50","S50-55","S55-60")
head(sizeclassbrfids)
##      S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50 S50-55 S55-60
## [1,]      0      0      1     18     18      1      1      0      0      0
sizeclassbrfid<-rbind(sizeclassbrfidn,sizeclassbrfidh,sizeclassbrfids)
rownames(sizeclassbrfid)<-c("BrooderFidalgo","BrooderDabob","BrooderOysterBay")
head(sizeclassbrfid)
##                  S10-15 S15-20 S20-25 S25-30 S30-35 S35-40 S40-45 S45-50
## BrooderFidalgo        0      1      0      2      4      1      0      0
## BrooderDabob          0      1      5      1      1      0      0      0
## BrooderOysterBay      0      0      1     18     18      1      1      0
##                  S50-55 S55-60
## BrooderFidalgo        0      0
## BrooderDabob          0      0
## BrooderOysterBay      0      0
brvpopsize<-t(rbind(sizeclassfid,sizeclassbrfid))
brvpopsizedf<-as.data.frame(brvpopsize)
brvpopsizedf$PercBroodFid<-(brvpopsizedf$BrooderFidalgo/brvpopsizedf$Fidalgo)
brvpopsizedf$PercBroodDab<-(brvpopsizedf$BrooderDabob/brvpopsizedf$Dabob)
brvpopsizedf$PercBroodOys<-(brvpopsizedf$BrooderOysterBay/brvpopsizedf$OysterBay)
brvpszfx<-rapply(brvpopsizedf, f=function(x)ifelse(is.nan(x),0,x),how="replace")
brvp<-data.frame(brvpszfx)

brvp$SizeClass=c("10-15mm","15-20mm","20-25mm","25-30mm","30-35mm","35-40mm","40-45mm","45-50mm","50-55mm","55-60mm")

ggplot()+geom_bar(data=brvp, aes(x=SizeClass,y=PercBroodFid),color="purple", fill="purple",stat="identity")+geom_bar(data=brvp,aes(x=SizeClass, y=PercBroodDab),color="blue",fill="blue",stat="identity")+geom_bar(data=brvp, aes(x=SizeClass,y=PercBroodOys),color="orange",fill="orange",stat="identity")

plot of chunk unnamed-chunk-1

brvp$PercSizeFidalgo<-(brvp$Fidalgo/(sum(brvp$Fidalgo)))
brvp$PercSizeOysBay<-(brvp$OysterBay/(sum(brvp$OysterBay)))
brvp$PercSizeDabob<-(brvp$Dabob/(sum(brvp$Dabob)))
brvp$BrSzPercFidalgo<-(brvp$PercBroodFid*brvp$PercSizeFidalgo)
brvp$BrSzPercDabob<-(brvp$PercBroodDab*brvp$PercSizeDabob)
brvp$BrSzPercOysBay<-(brvp$PercBroodOys*brvp$PercSizeOysBay)

BRvP<-read.csv('BRvP.csv')
View(BRvP)
ggplot(BRvP, aes(x=SizeClass, y=BrSzPercPop, group=Pop, color=Pop, fill=Pop))+geom_bar(binwidth=10, stat="identity", position=position_dodge())+scale_colour_manual(values=c("blue","purple","orange"))+scale_fill_manual(values=c("blue","purple","orange"))+labs(x="Size Class", y="Percent of Pop. Brooding at Size Class")

plot of chunk unnamed-chunk-1

ggplot(BRvP, aes(x=SizeClass, y=NoBrood, group=Pop, color=Pop, fill=Pop))+geom_bar(binwidth=10, stat="identity", position=position_dodge())+scale_colour_manual(values=c("blue","purple","orange"))+scale_fill_manual(values=c("blue","purple","orange"))+labs(x="Size Class", y="Number of Pop. Brooding at Size Class")

plot of chunk unnamed-chunk-1

No comments:

Post a Comment