2016-03-30 67 views
0

我無法弄清楚如何將正確的鍵添加到下面的圖中。請幫忙。關鍵應具有後跟適當的顏色的線(對於努力和Catchrate)文本c("Totalcatch","Effort","Catchrate"),且將適當PCH(用於totalcatch矩形,15和16爲其他兩個變量。)需要幫助構建雙倍的屏幕鍵

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)) 

如果你可以在這個過程中簡化我的代碼,它也會很棒。

回答

0

這似乎在一定程度上工作。但如果有人有一個更簡單的解決方案,請發佈。

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) 
key=list(text=list("Totalcatch",col="#0080ff"),rectangle=list(col="#0080ff"),text=list("Catchrate"),lines=list(col=1,type="b",pch=16),text=list("Effort",col=2),lines=list(col=2,type="b",pch=15),corner=c(0,1)) 
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)),key=key,col="#0080ff",ylab="Totalcatch") 
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))