I couldn't work out how to add the correct key to the plot below. Please help. The key should have the text c("Totalcatch","Effort","Catchrate") followed by the lines of the appropriate colour (for Effort and Catchrate), and the appropriate pch (a rectangle for totalcatch, 15 and 16 for the other two variables.)
library(latticeExtra)
Catchrate<-c(0.05, 0.18, 0.25, 0.31, 0.32, 0.34, 0.35)
totalcatch<-c(20, 30, 20, 30, 40, 50, 60)
Effort<-c(0, 1000, 2000, 3000, 4000, 5000, 6000)
year<-(2009:2015)
p1=barchart(totalcatch~as.factor(year),horizontal=FALSE,ylim=c(0,70),xlim=c(0,7.5),scales=list(y=list(axs="i"),x=list(at=1:7,labels=year)))
p2=xyplot(Effort~as.factor(year),type="b",col=2,scales=list(y=list(axs="i",draw=TRUE)),pch=15,par.settings=simpleTheme(col=2),ylab=list(label="Effort",col=2))
p3=xyplot(Catchrate~as.factor(year),type="b",pch=16,col=1,scales=list(y=list(draw=FALSE,axs="i",limit=c(0,0.4))))+layer(panel.axis(side="left",half=FALSE,tck=1,ticks=TRUE,at=seq(0.05,0.35,by=0.05),label=seq(0.05,0.35,by=0.05),line.col=1,text.col=1))
doubleYScale(doubleYScale(p1,p2,add.ylab2=TRUE,style2=4),p3)+layer(panel.text(0.8,40,label="Catchrate",srt=90))
If you could simplify my code in the process it will also be great.
