-
Notifications
You must be signed in to change notification settings - Fork 1
/
99_data_plots.R
50 lines (43 loc) · 1.76 KB
/
99_data_plots.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# curplot=T; slpplot=T; x=Cobs[1,]; anncol = "#0000ff99"; anncol2 ="green"
exp_trend = function(x, Iyr=95, yrs, nyears,ylab="",
curplot=F, slpplot=F, muplot = F, relplot=F,
anncol = "#0000ff99",anncol2 ="green",pos="left",
pointcol="#999999", smoothcol ="#ff000099" ){
Is<-smooth2(x,plot=F)
ind = 1:Iyr
plot(yrs[ind],x[ind],pch=19,ylim=c(0,quantile(x,0.99)),col=pointcol,xlab="",ylab=""); grid()
abline(v=yrs[nyears]+0.5,lty=2,lwd=2)
lines(yrs[ind],Is[ind],col=smoothcol,lwd=2)
cur<-Is[Iyr]
if(curplot){
points(yrs[Iyr],cur,pch=2,cex=2,lwd=2,col=anncol)
legend(pos,legend="Current smoothed value (c)",bty='n',cex=1,text.col=anncol)
}
if(slpplot){
s5<-slp3(Is[Iyr-(5:1)])
s10<-slp3(Is[Iyr-(10:1)])
abline(v=yrs[Iyr]-c(6,11),col=c(anncol,anncol2),lwd=2,lty=2)
xs= c(1,Iyr)
liney = exp(s5*xs) *mean(Is[Iyr-(5:1)])
mumean = mean(Is[Iyr-(5:1)])
yatx = approx(c(1,Iyr),liney,Iyr-3.5)$y
lines(yrs[xs],liney*mumean/yatx,col=anncol)
liney = exp(s10*xs) *mean(Is[Iyr-(10:1)])
mumean = mean(Is[Iyr-(10:1)])
yatx = approx(c(1,Iyr),liney,Iyr-6)$y
lines(yrs[xs],liney*mumean/yatx,col=anncol2)
legend(pos,legend=c("Smoothed slope last 5 years (5)", "Smoothed slope last 10 years (10)"),
text.col=c(anncol, anncol2),bty="n")
}
if(muplot){
mu = mean(x[nyears:Iyr])
lines(yrs[c(nyears,Iyr)],rep(mu,2),col=anncol,lwd=2)
legend(pos,legend=c("Mean value in projection (m)"),bty="n",text.col=anncol)
}
if(relplot){
allmu = mean(x[1:Iyr])
abline(h=allmu,col=anncol,lwd=2)
points(yrs[Iyr],cur,pch=2,cex=2,lwd=2,col=anncol)
legend(pos,legend=c("Current value relative to series mean (r)"),bty="n",text.col=anncol)
}
}