#Lat and Lon from 

rm(list=ls())
require(rworldmap)  
require(rworldxtra) 
quartz(width=7.5,height=7.5)

out=read.csv("SBTS19_Lobsters_ESD_ProtocolData.csv")
attach(out)
NN=length(LAT)
Nmax=max(N)
l2N=log(N,2)
par(mar=c(2,2,2,0.5))
plot(c(-74,-65.5),c(40,45.5), typ='n',main="Spring-2019 NOAA-NMFS Number N of Lobsters in trawl & k ESD") 
plot(add=TRUE, getMap(resolution = "high", projection=NA))

points(LON[K==0],LAT[K==0],cex=(l2N[K==0]+0.5)*0.4, col='red',lwd=2)
text(LON[K==0],LAT[K==0],STATION, col='black', pos=4, cex=0.4, offset=0.25)
mtext(date(),line=-1,adj=0)

detach(out)
#####
OUT=read.csv("Rev_SBTS19_Lobster_Biol_Data4ChiSq.csv")
attach(OUT)
l2N=log(N,2)
# NN=length(Lat)
# Nmax=max(N)
# plot(c(-74,-65.5),c(40,45.5), typ='n',main="Spring-2019 NOAA-NMFS Number of ESD & total Lobsters in trawl") 
# plot(add=TRUE, getMap(resolution = "high", projection=NA))

points(Lon,Lat,cex=(l2N+0.5)*0.4, col='red',lwd=2)
text(Lon,Lat,Trawl, col='blue', pos=4, cex=0.4, offset=0.25)
mtext(date(),line=-1,adj=0)
points(Lon,Lat,cex=(K+0.5)*0.4, col='blue',lwd=2)
print(names(OUT))
detach(OUT)

######

out=read.csv("ne50fathbl.csv")
attach(out)
lines(Fath50Lon[c(1:499,NA,500:553,NA,575:620)],Fath50Lat[c(1:499,NA,500:553,NA,575:620)], col='green')
# lines(Fath50Lon[c(500:553)],Fath50Lat[c(500:553)], col='red')
detach(out)

out=read.csv("necoast.csv", comment.char = "#")
attach(out)
len=length(neborderlon)
lines(neborderlon[c(1:len)],neborderlat[c(1:len)], col='grey')
detach(out)



YY=read.csv("NantucketShoals.csv")
attach(YY)
points(Lon,Lat,typ='l',col='purple',lwd=2)
detach(YY)
 text(-69.70,41.25,"avoid",cex=0.5, col='purple')
 text(-69.75,41.10,"Nantucket",cex=0.5)
 text(-69.75,40.90,"Shoals",cex=0.5)
 text(-67.6,41.45,"Georges Bank",cex=0.5)
 text(-66.5,42.00,"NE Peak",cex=0.5)
 text(-66.3,43.25,"Scotian Shoals",cex=0.5)
 text(-69,42,"Wilkinson Basin",cex=0.5)
 text(-70.15,42.9,"Jeffrey's Ledge",cex=0.4,srt=60)
 text(-67.60,43.25,"Jordan Basin",cex=0.5)
 text(-67.7,42.35,"Georges Basin",cex=0.5)
 text(-66.1,42.7,"Browns Bank",cex=0.4, srt=-12)
 text(-66.25,42.25,"NE Channel",cex=0.5, srt=-20)
 text(-69.18,41.40,"South Channel",cex=0.5, srt=-80)
 text(-70.34,41.98,"Cape Cod Bay",cex=0.3,srt=-10)
 text(-70.88,42.37,"Bos Hbr",cex=0.4,srt=40)
 text(-68.81,44.25,"Penobscot Bay",cex=0.4,srt=-67)
 text(-70.05,43.70,"Casco Bay",cex=0.3,srt=10)
 text(-69.5,44.75,"ME",cex=1)
 text(-65.5,44,"NS",cex=1)
 text(-71.6,43.2,"NH",cex=1)
 text(-72.8,43,"VT",cex=1)
 text(-70.9,42.3,"MA",cex=1)
 text(-72.6,41.5,"CT",cex=1)
 text(-74,41.5,"NY",cex=1)

rad=c(1,5,10,20,40,80,160)+0.49
loc=44.75-(0:6)*0.22
points(rep(-73.5,7), loc,cex=(log(rad,2))*0.4, col='red',lwd=2)
text(rep(-72.75,7),loc,round(rad), col='red', pos=4, cex=0.8)
text(-73.00,44.9,"Symbol    N lobsters",cex=0.9, col='red')
lines(c(-74.2,-74.2,-72,-72,-74.2),c(43.1,45.1,45.1,43.1,43.1),col='red',lwd=3)

rad=c(1,2,3,4)
loc=42.5-(0:3)*0.20
xpos=-73.7
yup=loc[1]+0.3; ydn=loc[4]-0.1
points(rep(xpos,4), loc,cex=rad*0.4, col='blue',lwd=2)
text(rep(xpos+0.7,4),loc,rad, col='blue', pos=4, cex=0.8)
text(xpos+0.6,yup-0.15,"Symbol   k with ESD",cex=0.9, col='blue')
xlp=xpos-0.5
lines(c(xlp,xlp,xlp+2.2,xlp+2.2,xlp),c(ydn,yup,yup,ydn,ydn),col='blue',lwd=3)

# rad=c(1,2,3,4,5,6)
rad=c(NA,NA,8,23,6,29)
locx=-66.9+(0:1)*0.7
locy=40.25-(0:2)*0.20
xpos=locx[c(1,1,1,2,2,2)]
ypos=locy[c(1,2,3,1,2,3)]
text(xpos,ypos, rad, col='blue', pos=4, cex=1.2)
text(xpos[1:2],ypos[1:2], 'NA', col='blue', pos=4, cex=1.2)
text(xpos[1]+0.7,ypos[1]+0.35,"ESD",cex=1.2, col='brown')
text(xpos[1]+0.8,ypos[1]+0.2,"Male  | Female",cex=0.9, col='brown')
xlp=xpos[1]-0.3
ylp=ypos[c(1:3)]+ 0.125
lines(c(xlp,xlp,xlp+2,xlp+2,xlp,NA,xlp,xlp+2,NA,xlp+1,xlp+1),c(ylp[3],ylp[1],ylp[1],ylp[3],ylp[3],NA,ylp[2],ylp[2],NA,ylp[1],ylp[3]),col='brown',lwd=3)
text(xlp-0.5,locy[1],"Egg",cex=0.9, col='brown')
text(xlp-0.5,locy[2],"No Egg",cex=0.9, col='brown')
text(xlp-0.5,locy[3],"Total:",cex=0.9, col='brown')

text(-69.00,45.5,"ESD trawl # in blue",cex=0.9, col='blue')
text(-69.00,45.3,"no-ESD trawl # in black",cex=0.9, col='black')
text(-69.00,45.1,"37 ESD of 2038 examined =1.8% ESD",cex=0.9, col='red')
