################
# Code for plotting Fig. 2: biodiversity~herbicide effects
# Kormann et al. Ecol. Apps 2021
# Code by urs.kormann@vogelwarte.ch


## read in the table. Note that for the Bayesian birds, the notion whether the changewas considered "significant" or not were based on intervall overlap
setwd("~/Documents/Manuskripte/2018/IFM_Synthesis/aaa_Eco_Apps_Final/data")
########
# Now set up a dummy, that codes for the transparency. Should be 1 for significant p values, 
# and 0.3 for not significant p values
##
d4=read.csv("overview_herbicide_biodiv_effects.csv",header=T)
d4$Treatment<- factor(d4$Treatment, levels = c("CONTROL", "LIGHT", "MODERATE", "INTENSIVE"))
str(d4)
d4$sig_dummy_sr <- 1
d4$sig_dummy_abu <- 1

d4
d4$line_dummy_sr <- 3
d4$line_dummy_abu <- 3

names(d4)
d4[d4$p_sr > 0.05,]$sig_dummy_sr <-0.6
d4[d4$p_abu > 0.05,]$sig_dummy_abu <-0.6

#d4[d4$p_sr > 0.1,]$sig_dummy_sr <-0.3
#d4[d4$p_abu > 0.1,]$sig_dummy_abu <-0.3


d4[d4$p_sr < 0.05,]$line_dummy_sr <-3
d4[d4$p_abu < 0.05,]$line_dummy_abu <-3

d4$pch_sr <- 999
d4$pch_abu <- 999

d4[d4$p_sr < 0.05,]$pch_sr <-16
d4[d4$p_sr > 0.05,]$pch_sr <-1

d4[d4$p_abu < 0.05,]$pch_abu <-16
d4[d4$p_abu > 0.05,]$pch_abu <-1

###########################
##### plot species richness 
###########################
#pdf("file_abu4.pdf",width=1.5,height=8,paper='special')

# woody species
par(mfrow= c (9,1))
par(mar=c(2,1,1,1))
names(d4)
plot( yaxt='n',d4$pred_sr[1:4], d4$Treatment[1:4], xlim = c(min(d4$lower_sr[1:4]), max(d4$upper_sr[1:4])),col = "white", xlab = "", ylab = "",ylim = c(0.5, 4.5))

segments(y0 = 4, x0 = d4$lower_sr[1], y1= 4,lwd = d4$line_dummy_sr[1], x1=d4$upper_sr[1], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[2], y1= 3,lwd = d4$line_dummy_sr[2], x1=d4$upper_sr[2], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[3], y1= 2,lwd = d4$line_dummy_sr[3], x1=d4$upper_sr[3], col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[4], y1= 1, lwd = d4$line_dummy_sr[4],x1=d4$upper_sr[4], col ="red")

points(d4$pred_sr[1],pch =d4$pch_sr[1],4,cex = 2,  col = "darkgreen")
points(d4$pred_sr[2],pch =d4$pch_sr[2],3,cex = 2,  col = "blue" )
points(d4$pred_sr[3],pch =d4$pch_sr[3],2,cex = 2,  col = "orange" )
points(d4$pred_sr[4],pch =d4$pch_sr[4],1,cex = 2,  col = "red" )


#herbs
plot( yaxt='n',d4$pred_sr[5:8], d4$Treatment[5:8], xlim = c(min(d4$lower_sr[5:8]), max(d4$upper_sr[5:8])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_sr[5], y1= 4,lwd = d4$line_dummy_sr[5], x1=d4$upper_sr[5], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[6], y1= 3, lwd = d4$line_dummy_sr[6],x1=d4$upper_sr[6], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[7], y1= 2,lwd = d4$line_dummy_sr[7], x1=d4$upper_sr[7], col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[8], y1= 1,lwd = d4$line_dummy_sr[8], x1=d4$upper_sr[8], col = "red")

points(d4$pred_sr[5],pch =d4$pch_sr[5],4,cex = 2,  col = "darkgreen" )
points(d4$pred_sr[6],pch =d4$pch_sr[6],3,cex = 2,  col = "blue" )
points(d4$pred_sr[7],pch =d4$pch_sr[7],2,cex = 2,  col = "orange" )
points(d4$pred_sr[8],pch =d4$pch_sr[8],1,cex = 2,  col = "red" )

# flowers
plot( yaxt='n',d4$pred_sr[9:12], d4$Treatment[9:12], xlim = c(min(d4$lower_sr[9:12]), max(d4$upper_sr[9:12])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_sr[9], y1= 4, x1=d4$upper_sr[9], lwd = d4$line_dummy_sr[9],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[10], y1= 3, x1=d4$upper_sr[10],lwd = d4$line_dummy_sr[10], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[11], y1= 2, x1=d4$upper_sr[11], lwd = d4$line_dummy_sr[11],col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[12], y1= 1, x1=d4$upper_sr[12], lwd = d4$line_dummy_sr[12],col = "red")

points(d4$pred_sr[9],pch =d4$pch_sr[9],4,cex = 2,  col = "darkgreen" )
points(d4$pred_sr[10],pch =d4$pch_sr[10],3,cex = 2,  col = "blue")
points(d4$pred_sr[11],pch =d4$pch_sr[11],2,cex = 2,  col = "orange" )
points(d4$pred_sr[12],pch =d4$pch_sr[12],1,cex = 2,  col = "red" )

## birds gleaners early
plot( yaxt='n',d4$pred_sr[13:20], d4$Treatment[13:20], xlim = c(min(d4$lower_sr[13:28]), max(d4$upper_sr[13:28])),col = "white", xlab = "", ylim = c(0, 4))

segments(y0 = 3.5, x0 = d4$lower_sr[13], y1= 3.5,lwd = d4$line_dummy_sr[13], x1=d4$upper_sr[13], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_sr[14], y1= 2.5, lwd = d4$line_dummy_sr[14],x1=d4$upper_sr[14], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_sr[15], y1= 1.5, lwd = d4$line_dummy_sr[15],x1=d4$upper_sr[15], col = "orange")
segments(y0 = .5, x0 = d4$lower_sr[16], y1= .5,lwd = d4$line_dummy_sr[16], x1=d4$upper_sr[16], col = "red")

points(d4$pred_sr[13],3.5,cex = 2,  col = "darkgreen" , pch = 17)
points(d4$pred_sr[14],2.5,cex = 2,  col = "blue", pch = 2)
points(d4$pred_sr[15],1.5,cex = 2,  col = "orange", pch = 17)
points(d4$pred_sr[16],0.5,cex = 2,  col = "red" ,  pch = 17)

#non gleaners
segments(y0 = 3.5, x0 = d4$lower_sr[17], y1= 3.5,lwd = d4$line_dummy_sr[17], x1=d4$upper_sr[17], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_sr[18], y1= 2.5, lwd = d4$line_dummy_sr[18],x1=d4$upper_sr[18], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_sr[19], y1= 1.5, lwd = d4$line_dummy_sr[19],x1=d4$upper_sr[19], col = "orange")
segments(y0 = .5, x0 = d4$lower_sr[20], y1= .5,lwd = d4$line_dummy_sr[20], x1=d4$upper_sr[20], col = "red")

points(d4$pred_sr[17],3.5,cex = 2,  col = "darkgreen", pch = 15)
points(d4$pred_sr[18],2.5,cex = 2,  col = "blue", pch = 0)
points(d4$pred_sr[19],1.5,cex = 2,  col = "orange" , pch = 0)
points(d4$pred_sr[20],.5,cex = 2,  col = "red" , pch = 0)
#
# birds mid
plot( yaxt='n',d4$pred_sr[21:28], d4$Treatment[21:28], xlim = c(min(d4$lower_sr[13:28]), max(d4$upper_sr[13:28])),col = "white", xlab = "", ylim = c(0, 4))

segments(y0 = 3.5, x0 = d4$lower_sr[21], y1= 3.5,lwd = d4$line_dummy_sr[21], x1=d4$upper_sr[21], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_sr[22], y1= 2.5, lwd = d4$line_dummy_sr[22],x1=d4$upper_sr[22], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_sr[23], y1= 1.5, lwd = d4$line_dummy_sr[23],x1=d4$upper_sr[23], col = "orange")
segments(y0 = .5, x0 = d4$lower_sr[24], y1= .5,lwd = d4$line_dummy_sr[24], x1=d4$upper_sr[24], col = "red")

points(d4$pred_sr[21],3.5,cex = 2,  col = "darkgreen" ,   pch = 17)
points(d4$pred_sr[22],2.5,cex = 2,  col = "blue",   pch = 2)
points(d4$pred_sr[23],1.5,cex = 2,  col = "orange" ,   pch = 2)
points(d4$pred_sr[24],.5,cex = 2,  col = "red",   pch = 2)

#non gleaners mid
segments(y0 = 3.5, x0 = d4$lower_sr[25], y1= 3.5,lwd = d4$line_dummy_sr[25], x1=d4$upper_sr[25], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_sr[26], y1= 2.5, lwd = d4$line_dummy_sr[26],x1=d4$upper_sr[26], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_sr[27], y1= 1.5, lwd = d4$line_dummy_sr[27],x1=d4$upper_sr[27], col = "orange")
segments(y0 = .5, x0 = d4$lower_sr[28], y1= .5,lwd = d4$line_dummy_sr[28], x1=d4$upper_sr[28], col = "red")

points(d4$pred_sr[25],3.5,cex = 2,  col = "darkgreen" , pch = 15)
points(d4$pred_sr[26],2.5,cex = 2,  col = "blue", pch = 0)
points(d4$pred_sr[27],1.5,cex = 2,  col = "orange" , pch = 0)
points(d4$pred_sr[28],.5,cex = 2,  col = "red", pch = 0)

# pollinators

plot( yaxt='n',d4$pred_sr[29:32], d4$Treatment[29:32], xlim = c(min(d4$lower_sr[29:32]), max(d4$upper_sr[29:32])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_sr[29], y1= 4, x1=d4$upper_sr[29], lwd = d4$line_dummy_sr[29],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[30], y1= 3, x1=d4$upper_sr[30],lwd = d4$line_dummy_sr[30], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[31], y1= 2, x1=d4$upper_sr[31], lwd = d4$line_dummy_sr[31],col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[32], y1= 1, x1=d4$upper_sr[32], lwd = d4$line_dummy_sr[32],col = "red")

points(d4$pred_sr[29],pch =d4$pch_sr[29],4,cex = 2,  col = "darkgreen" )
points(d4$pred_sr[30],pch =d4$pch_sr[30],3,cex = 2,  col = "blue")
points(d4$pred_sr[31],pch =d4$pch_sr[31],2,cex = 2,  col = "orange" )
points(d4$pred_sr[32],pch =d4$pch_sr[32],1,cex = 2,  col = "red" )

#Arthropods
plot( yaxt='n',d4$pred_sr[33:36], d4$Treatment[33:36], xlim = c(min(d4$lower_sr[33:36]), max(d4$upper_sr[33:36])),col = "white", xlab = "", ylim = c(0.5, 4.5))

segments(y0 = 4, x0 = d4$lower_sr[33], y1= 4, x1=d4$upper_sr[33], lwd = d4$line_dummy_sr[33],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[34], y1= 3, x1=d4$upper_sr[34],lwd = d4$line_dummy_sr[34], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[35], y1= 2, x1=d4$upper_sr[35], lwd = d4$line_dummy_sr[35],col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[36], y1= 1, x1=d4$upper_sr[36], lwd = d4$line_dummy_sr[36],col = "red")

points(d4$pred_sr[33],pch =d4$pch_sr[33],4,cex = 2,  col = "darkgreen" )
points(d4$pred_sr[34],pch =d4$pch_sr[34],3,cex = 2,  col = "blue" )
points(d4$pred_sr[35],pch =d4$pch_sr[35],2,cex = 2,  col = "orange" )
points(d4$pred_sr[36],pch =d4$pch_sr[36],1,cex = 2,  col = "red" )

#Moths
plot( yaxt='n',d4$pred_sr[37:40], d4$Treatment[37:40], xlim = c(min(d4$lower_sr[37:40]), max(d4$upper_sr[37:40])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_sr[37], y1= 4, x1=d4$upper_sr[37], lwd = d4$line_dummy_sr[37],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_sr[38], y1= 3, x1=d4$upper_sr[38],lwd = d4$line_dummy_sr[38], col = "blue")
segments(y0 = 2, x0 = d4$lower_sr[39], y1= 2, x1=d4$upper_sr[39], lwd = d4$line_dummy_sr[39],col = "orange")
segments(y0 = 1, x0 = d4$lower_sr[40], y1= 1, x1=d4$upper_sr[40], lwd = d4$line_dummy_sr[40],col = "red")

points(d4$pred_sr[37],pch =d4$pch_sr[37],4,cex = 2,  col = "darkgreen")
points(d4$pred_sr[38],pch =d4$pch_sr[38],3,cex = 2,  col = "blue" )
points(d4$pred_sr[39],pch =d4$pch_sr[39],2,cex = 2,  col = "orange")
points(d4$pred_sr[40],pch =d4$pch_sr[40],1,cex = 2,  col = "red")


################
# Plot abundances 
###############
#pdf("file_abu4.pdf",width=1.5,height=8,paper='special')
par(mfrow= c (9,1))
par(mar=c(2,1,1,1))
names(d4)


# woody species 
plot( yaxt='n',d4$pred_abu[1:4], d4$Treatment[1:4], xlim = c(min(d4$lower_abu[1:4]), max(d4$upper_abu[1:4])),col = "white", xlab = "", ylab = "",ylim = c(0.5, 4.5))
#title("A", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_abu[1], y1= 4,lwd = d4$line_dummy_abu[1], x1=d4$upper_abu[1], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[2], y1= 3,lwd = d4$line_dummy_abu[2], x1=d4$upper_abu[2], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[3], y1= 2,lwd = d4$line_dummy_abu[3], x1=d4$upper_abu[3], col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[4], y1= 1, lwd = d4$line_dummy_abu[4],x1=d4$upper_abu[4], col = "red")

points(d4$pred_abu[1],pch =d4$pch_abu[1],4,cex = 2,  col = "darkgreen") 
points(d4$pred_abu[2],pch =d4$pch_abu[2],3,cex = 2,  col = "blue") 
points(d4$pred_abu[3],pch =d4$pch_abu[3],2,cex = 2,  col = "orange")
points(d4$pred_abu[4],pch =d4$pch_abu[4],1,cex = 2,  col = "red")

# Herbs
plot( yaxt='n',d4$pred_abu[5:8], d4$Treatment[5:8], xlim = c(min(d4$lower_abu[5:8]), max(d4$upper_abu[5:8])),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("D", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_abu[5], y1= 4,lwd = d4$line_dummy_abu[5], x1=d4$upper_abu[5], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[6], y1= 3, lwd = d4$line_dummy_abu[6],x1=d4$upper_abu[6], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[7], y1= 2,lwd = d4$line_dummy_abu[7], x1=d4$upper_abu[7], col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[8], y1= 1,lwd = d4$line_dummy_abu[8], x1=d4$upper_abu[8], col = "red")

points(d4$pred_abu[5],pch =d4$pch_abu[5],4,cex = 2,  col = "darkgreen")
points(d4$pred_abu[6],pch =d4$pch_abu[6],3,cex = 2,  col = "blue")
points(d4$pred_abu[7],pch =d4$pch_abu[7],2,cex = 2,  col = "orange")
points(d4$pred_abu[8],pch =d4$pch_abu[8],1,cex = 2,  col = "red")

# Flowers
plot( yaxt='n',d4$pred_abu[9:12], d4$Treatment[9:12], xlim = c(min(d4$lower_abu[9:12]), max(d4$upper_abu[9:12])),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("G", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_abu[9], y1= 4, x1=d4$upper_abu[9], lwd = d4$line_dummy_abu[9],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[10], y1= 3, x1=d4$upper_abu[10],lwd = d4$line_dummy_abu[10], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[11], y1= 2, x1=d4$upper_abu[11], lwd = d4$line_dummy_abu[11],col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[12], y1= 1, x1=d4$upper_abu[12], lwd = d4$line_dummy_abu[12],col = "red")

points(d4$pred_abu[9],pch =d4$pch_abu[9],4,cex = 2,  col = "darkgreen")
points(d4$pred_abu[10],pch =d4$pch_abu[10],3,cex = 2,  col = "blue")
points(d4$pred_abu[11],pch =d4$pch_abu[11],2,cex = 2,  col = "orange")
points(d4$pred_abu[12],pch =d4$pch_abu[12],1,cex = 2,  col = "red")

## birds early
plot( yaxt='n',d4$pred_abu[13:20], d4$Treatment[13:20], xlim = c(0, 280),col = "white", xlab = "", ylim = c(0, 4))

segments(y0 = 3.5, x0 = d4$lower_abu[13], y1= 3.5,lwd = d4$line_dummy_abu[13], x1=d4$upper_abu[13], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_abu[14], y1= 2.5, lwd = d4$line_dummy_abu[14],x1=d4$upper_abu[14], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_abu[15], y1= 1.5, lwd = d4$line_dummy_abu[15],x1=d4$upper_abu[15], col = "orange")
segments(y0 = .5, x0 = d4$lower_abu[16], y1= .5,lwd = d4$line_dummy_abu[16], x1=d4$upper_abu[16], col = "red")

points(d4$pred_abu[13],3.5,cex = 2,  col = "darkgreen" , pch = 17)
points(d4$pred_abu[14],2.5,cex = 2,  col = "blue", pch = 2)
points(d4$pred_abu[15],1.5,cex = 2,  col = "orange", pch = 17)
points(d4$pred_abu[16],0.5,cex = 2,  col = "red" ,  pch = 17)

#non gleaners
segments(y0 = 3.5, x0 = d4$lower_abu[17], y1= 3.5,lwd = d4$line_dummy_abu[17], x1=d4$upper_abu[17], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_abu[18], y1= 2.5, lwd = d4$line_dummy_abu[18],x1=d4$upper_abu[18], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_abu[19], y1= 1.5, lwd = d4$line_dummy_abu[19],x1=d4$upper_abu[19], col = "orange")
segments(y0 = .5, x0 = d4$lower_abu[20], y1= .5,lwd = d4$line_dummy_abu[20], x1=d4$upper_abu[20], col = "red")

points(d4$pred_abu[17],3.5,cex = 2,  col = "darkgreen", pch = 15)
points(d4$pred_abu[18],2.5,cex = 2,  col = "blue", pch = 0)
points(d4$pred_abu[19],1.5,cex = 2,  col = "orange" , pch = 0)
points(d4$pred_abu[20],.5,cex = 2,  col = "red" , pch = 0)
#
# birds mid
plot( yaxt='n',d4$pred_abu[21:28], d4$Treatment[21:28], xlim = c(min(d4$lower_abu[13:28]), max(d4$upper_abu[13:28])),col = "white", xlab = "", ylim = c(0, 4))

segments(y0 = 3.5, x0 = d4$lower_abu[21], y1= 3.5,lwd = d4$line_dummy_abu[21], x1=d4$upper_abu[21], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_abu[22], y1= 2.5, lwd = d4$line_dummy_abu[22],x1=d4$upper_abu[22], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_abu[23], y1= 1.5, lwd = d4$line_dummy_abu[23],x1=d4$upper_abu[23], col = "orange")
segments(y0 = .5, x0 = d4$lower_abu[24], y1= .5,lwd = d4$line_dummy_abu[24], x1=d4$upper_abu[24], col = "red")

points(d4$pred_abu[21],3.5,cex = 2,  col = "darkgreen" ,   pch = 17)
points(d4$pred_abu[22],2.5,cex = 2,  col = "blue",   pch = 2)
points(d4$pred_abu[23],1.5,cex = 2,  col = "orange" ,   pch = 2)
points(d4$pred_abu[24],.5,cex = 2,  col = "red",   pch = 2)

#non gleaners mid
segments(y0 = 3.5, x0 = d4$lower_abu[25], y1= 3.5,lwd = d4$line_dummy_abu[25], x1=d4$upper_abu[25], col = "darkgreen")
segments(y0 = 2.5, x0 = d4$lower_abu[26], y1= 2.5, lwd = d4$line_dummy_abu[26],x1=d4$upper_abu[26], col = "blue")
segments(y0 = 1.5, x0 = d4$lower_abu[27], y1= 1.5, lwd = d4$line_dummy_abu[27],x1=d4$upper_abu[27], col = "orange")
segments(y0 = .5, x0 = d4$lower_abu[28], y1= .5,lwd = d4$line_dummy_abu[28], x1=d4$upper_abu[28], col = "red")

points(d4$pred_abu[25],3.5,cex = 2,  col = "darkgreen" , pch = 15)
points(d4$pred_abu[26],2.5,cex = 2,  col = "blue", pch = 0)
points(d4$pred_abu[27],1.5,cex = 2,  col = "orange" , pch = 0)
points(d4$pred_abu[28],.5,cex = 2,  col = "red", pch = 0)

# pollinators

plot( yaxt='n',d4$pred_abu[29:32], d4$Treatment[29:32], xlim = c(min(d4$lower_abu[29:32]), max(d4$upper_abu[29:32])),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("P", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_abu[29], y1= 4, x1=d4$upper_abu[29], lwd = d4$line_dummy_abu[29],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[30], y1= 3, x1=d4$upper_abu[30],lwd = d4$line_dummy_abu[30], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[31], y1= 2, x1=d4$upper_abu[31], lwd = d4$line_dummy_abu[31],col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[32], y1= 1, x1=d4$upper_abu[32], lwd = d4$line_dummy_abu[32],col = "red")

points(d4$pred_abu[29],pch =d4$pch_abu[29],4,cex = 2,  col = "darkgreen")
points(d4$pred_abu[30],pch =d4$pch_abu[30],3,cex = 2,  col = "blue")
points(d4$pred_abu[31],pch =d4$pch_abu[31],2,cex = 2,  col = "orange")
points(d4$pred_abu[32],pch =d4$pch_abu[32],1,cex = 2,  col = "red")

####arthopods
plot( yaxt='n',d4$pred_abu[33:36], d4$Treatment[33:36], xlim = c(min(d4$lower_abu[33:36]), max(d4$upper_abu[33:36])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_abu[33], y1= 4, x1=d4$upper_abu[33], lwd = d4$line_dummy_abu[33],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[34], y1= 3, x1=d4$upper_abu[34],lwd = d4$line_dummy_abu[34], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[35], y1= 2, x1=d4$upper_abu[35], lwd = d4$line_dummy_abu[35],col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[36], y1= 1, x1=d4$upper_abu[36], lwd = d4$line_dummy_abu[36],col = "red")

points(d4$pred_abu[33],pch =d4$pch_abu[33],4,cex = 2,  col = "darkgreen")
points(d4$pred_abu[34],pch =d4$pch_abu[34],3,cex = 2,  col = "blue" )
points(d4$pred_abu[35],pch =d4$pch_abu[35],2,cex = 2,  col = "orange" )
points(d4$pred_abu[36],pch =d4$pch_abu[36],1,cex = 2,  col = "red" )

###Moths 
plot(yaxt='n',d4$pred_abu[37:40], d4$Treatment[37:40], xlim = c(min(d4$lower_abu[37:40]), max(d4$upper_abu[37:40])),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_abu[37], y1= 4, x1=d4$upper_abu[37], lwd = d4$line_dummy_abu[37],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[38], y1= 3, x1=d4$upper_abu[38],lwd = d4$line_dummy_abu[38], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[39], y1= 2, x1=d4$upper_abu[39], lwd = d4$line_dummy_abu[39],col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[40], y1= 1, x1=d4$upper_abu[40], lwd = d4$line_dummy_abu[40],col = "red")

points(d4$pred_abu[37],pch =d4$pch_abu[37],4,cex = 2,  col = "darkgreen" )
points(d4$pred_abu[38],pch =d4$pch_abu[38],3,cex = 2,  col = "blue")
points(d4$pred_abu[39],pch =d4$pch_abu[39],2,cex = 2,  col = "orange" )
points(d4$pred_abu[40],pch =d4$pch_abu[40],1,cex = 2,  col = "red")

# ungulates
plot(yaxt='n', d4$pred_abu[41:44], d4$Treatment[41:44], xlim = c(100, 1500),col = "white", xlab = "", ylim = c(0.5, 4.5))
segments(y0 = 4, x0 = d4$lower_abu[41], y1= 4, x1=d4$upper_abu[41], lwd = d4$line_dummy_abu[41],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_abu[42], y1= 3, x1=d4$upper_abu[42],lwd = d4$line_dummy_abu[42], col = "blue")
segments(y0 = 2, x0 = d4$lower_abu[43], y1= 2, x1=d4$upper_abu[43], lwd = d4$line_dummy_abu[43],col = "orange")
segments(y0 = 1, x0 = d4$lower_abu[44], y1= 1, x1=d4$upper_abu[44], lwd = d4$line_dummy_abu[44],col = "red")

points(d4$pred_abu[41],pch =d4$pch_abu[41],4,cex = 2,  col = "darkgreen" )
points(d4$pred_abu[42],pch =d4$pch_abu[42],3,cex = 2,  col = "blue")
points(d4$pred_abu[43],pch =d4$pch_abu[43],2,cex = 2,  col = "orange")
points(d4$pred_abu[44],pch =d4$pch_abu[44],1,cex = 2,  col = "red")
###

dev.off()

#######
# SHIFT
#######


#########################


setwd("~/Documents/Oregon/IFM/IFM_Synthesis/Analyse/New_shift_March14")
d4 <- read.csv("shift_summary.csv") #read the main table

d4$sig_dummy_shift <- 3
d4$line_dummy_shift <- 2
names(d4)
#d4[d4$p_shift > 0.05,]$sig_dummy_shift <-0.6

d4$pch_shift <- 999

d4[d4$p_shift < 0.05,]$pch_shift <-16
d4[d4$p_shift > 0.05,]$pch_shift <-1

#
#####
#pdf("file_shift4.pdf",width=1.5,height=8,paper='special')
par(mfrow= c (9,1))
#par(mfrow= c (1,1))
par(mar=c(2,1,1,1))
names(d4)
plot( yaxt='n',d4$pred_shift[1:4], d4$Treatment[1:4], xlim = c(0.3, 1),col = "white", xlab = "", ylab = "",ylim = c(0.5, 4.5))
#title("C", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[1], y1= 4,lwd = d4$line_dummy_shift[1], x1=d4$upper_shift[1], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[2], y1= 3,lwd = d4$line_dummy_shift[2], x1=d4$upper_shift[2], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[3], y1= 2,lwd = d4$line_dummy_shift[3], x1=d4$upper_shift[3], col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[4], y1= 1, lwd = d4$line_dummy_shift[4],x1=d4$upper_shift[4], col = "red")

points(d4$pred_shift[1],pch =d4$pch_shift[1],4,cex = 2,  col = "darkgreen")
points(d4$pred_shift[2],pch =d4$pch_shift[2],3,cex = 2,  col = "blue")
points(d4$pred_shift[3],pch =d4$pch_shift[3],2,cex = 2,  col = "orange")
points(d4$pred_shift[4],pch =d4$pch_shift[4],1,cex = 2,  col = "red" )

par(mar=c(2,1,1,1))

plot( yaxt='n',d4$pred_shift[5:8], d4$Treatment[5:8], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("F", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[5], y1= 4,lwd = d4$line_dummy_shift[5], x1=d4$upper_shift[5], col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[6], y1= 3, lwd = d4$line_dummy_shift[6],x1=d4$upper_shift[6], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[7], y1= 2,lwd = d4$line_dummy_shift[7], x1=d4$upper_shift[7], col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[8], y1= 1,lwd = d4$line_dummy_shift[8], x1=d4$upper_shift[8], col = "red")

points(d4$pred_shift[5],pch =d4$pch_shift[5],4,cex = 2,  col = "darkgreen")
points(d4$pred_shift[6],pch =d4$pch_shift[6],3,cex = 2,  col = "blue" )
points(d4$pred_shift[7],pch =d4$pch_shift[7],2,cex = 2,  col = "orange" )
points(d4$pred_shift[8],pch =d4$pch_shift[8],1,cex = 2,  col = "red" )

par(mar=c(2,1,1,1))

plot( yaxt='n',d4$pred_shift[9:12], d4$Treatment[9:12], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("I", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[9], y1= 4, x1=d4$upper_shift[9], lwd = d4$line_dummy_shift[9],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[10], y1= 3, x1=d4$upper_shift[10],lwd = d4$line_dummy_shift[10], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[11], y1= 2, x1=d4$upper_shift[11], lwd = d4$line_dummy_shift[11],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[12], y1= 1, x1=d4$upper_shift[12], lwd = d4$line_dummy_shift[12],col = "red")

points(d4$pred_shift[9],pch =d4$pch_shift[9],4,cex = 2,  col = "darkgreen" )
points(d4$pred_shift[10],pch =d4$pch_shift[10],3,cex = 2,  col = "blue" )
points(d4$pred_shift[11],pch =d4$pch_shift[11],2,cex = 2,  col = "orange" )
points(d4$pred_shift[12],pch =d4$pch_shift[12],1,cex = 2,  col = "red" )

par(mar=c(2,1,1,1))

# bird early 

plot( yaxt='n',d4$pred_shift[13:20], d4$Treatment[13:20], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("L", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[13], y1= 4, x1=d4$upper_shift[13], lwd = d4$line_dummy_shift[13],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[14], y1= 3, x1=d4$upper_shift[14],lwd = d4$line_dummy_shift[14], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[15], y1= 2, x1=d4$upper_shift[15], lwd = d4$line_dummy_shift[15],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[16], y1= 1, x1=d4$upper_shift[16], lwd = d4$line_dummy_shift[16],col = "red")

points(d4$pred_shift[13],pch =d4$pch_shift[13],4,cex = 2,  col = "darkgreen")
points(d4$pred_shift[14],pch =d4$pch_shift[14],3,cex = 2,  col = "blue")
points(d4$pred_shift[15],pch =d4$pch_shift[15],2,cex = 2,  col = "orange" )
points(d4$pred_shift[16],pch =d4$pch_shift[16],1,cex = 2,  col = "red")

## birds mid

plot( yaxt='n',d4$pred_shift[13:20], d4$Treatment[13:20], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("Q", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[17], y1= 4, x1=d4$upper_shift[17], lwd = d4$line_dummy_shift[17],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[18], y1= 3, x1=d4$upper_shift[18],lwd = d4$line_dummy_shift[18], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[19], y1= 2, x1=d4$upper_shift[19], lwd = d4$line_dummy_shift[19],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[20], y1= 1, x1=d4$upper_shift[20], lwd = d4$line_dummy_shift[20],col = "red")

points(d4$pred_shift[17],pch =d4$pch_shift[17],4,cex = 2,  col = "darkgreen")
points(d4$pred_shift[18],pch =d4$pch_shift[18],3,cex = 2,  col = "blue" )
points(d4$pred_shift[19],pch =d4$pch_shift[19],2,cex = 2,  col = "orange")
points(d4$pred_shift[20],pch =d4$pch_shift[20],1,cex = 2,  col = "red")


## bees pollinators
plot( yaxt='n',d4$pred_shift[21:24], d4$Treatment[21:24], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("R", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[21], y1= 4, x1=d4$upper_shift[21], lwd = d4$line_dummy_shift[21],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[22], y1= 3, x1=d4$upper_shift[22],lwd = d4$line_dummy_shift[22], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[23], y1= 2, x1=d4$upper_shift[23], lwd = d4$line_dummy_shift[23],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[24], y1= 1, x1=d4$upper_shift[24], lwd = d4$line_dummy_shift[24],col = "red")

points(d4$pred_shift[21],pch =d4$pch_shift[21],4,cex = 2,  col = "darkgreen" )
points(d4$pred_shift[22],pch =d4$pch_shift[22],3,cex = 2,  col = "blue" )
points(d4$pred_shift[23],pch =d4$pch_shift[23],2,cex = 2,  col = "orange" )
points(d4$pred_shift[24],pch =d4$pch_shift[24],1,cex = 2,  col = "red" )

### arthropods

plot( yaxt='n',d4$pred_shift[25:28], d4$Treatment[25:28], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("U", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[25], y1= 4, x1=d4$upper_shift[25], lwd = d4$line_dummy_shift[25],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[26], y1= 3, x1=d4$upper_shift[26],lwd = d4$line_dummy_shift[26], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[27], y1= 2, x1=d4$upper_shift[27], lwd = d4$line_dummy_shift[27],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[28], y1= 1, x1=d4$upper_shift[28], lwd = d4$line_dummy_shift[28],col = "red")

points(d4$pred_shift[25],pch =d4$pch_shift[25],4,cex = 2,  col = "darkgreen")
points(d4$pred_shift[26],pch =d4$pch_shift[26],3,cex = 2,  col = "blue" )
points(d4$pred_shift[27],pch =d4$pch_shift[27],2,cex = 2,  col = "orange" )
points(d4$pred_shift[28],pch =d4$pch_shift[28],1,cex = 2,  col = "red" )


####moth

plot( yaxt='n',d4$pred_shift[29:32], d4$Treatment[29:32], xlim = c(0.3, 1),col = "white", xlab = "", ylim = c(0.5, 4.5))
#title("X", adj = 0.01,line = -1.05)
segments(y0 = 4, x0 = d4$lower_shift[29], y1= 4, x1=d4$upper_shift[29], lwd = d4$line_dummy_shift[29],col = "darkgreen")
segments(y0 = 3, x0 = d4$lower_shift[30], y1= 3, x1=d4$upper_shift[30],lwd = d4$line_dummy_shift[30], col = "blue")
segments(y0 = 2, x0 = d4$lower_shift[31], y1= 2, x1=d4$upper_shift[31], lwd = d4$line_dummy_shift[31],col = "orange")
segments(y0 = 1, x0 = d4$lower_shift[32], y1= 1, x1=d4$upper_shift[32], lwd = d4$line_dummy_shift[32],col = "red")

points(d4$pred_shift[29],pch =d4$pch_shift[29],4,cex = 2,  col = "darkgreen" )
points(d4$pred_shift[30],pch =d4$pch_shift[30],3,cex = 2,  col = "blue")
points(d4$pred_shift[31],pch =d4$pch_shift[31],2,cex = 2,  col = "orange" )
points(d4$pred_shift[32],pch =d4$pch_shift[32],1,cex = 2,  col = "red" )

dev.off()

