T&E.figures.R

File	Name:	T&E.figures.R

Author:	Abt	Associates	Inc.

Created:	5/27/2010

Updated:	2/5/2013

Purpose:	R	script	to	create	the	ECDF	plots	found	in	the	T&E	chapter	of	the	BA

setwd("~/Desktop/I&E/T&E Overlaps/T&E Tables/")

#library(countreg)

facs=read.csv("facilities.csv") # CBI list of facilities with overlap

facs$region[is.na(facs$region)] <- "NA"

facs[is.na(facs)] <- 0

spp=read.csv("species.csv") # CBI list of species count by facility overlaps

## ecdf plot of all facilities by species 

png(file="facility.all.ecdf.png",width=768,height=768,pointsize=24)

par(mfrow=c(1,1))

plot(ecdf(facs$all),verticals=TRUE,xlab="Species Overlaps per 

Facility",ylab="Cumulative Proportion of Facilities",xlim=c(-

.05,35),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1)

dev.off()

## ecdf plot of all species by facility

png(file="species.all.ecdf.png",width=768,height=768,pointsize=24)

par(mfrow=c(1,1))

plot(ecdf(spp$facilities),verticals=TRUE,xlab="Facility Overlaps per Impacted 

Species",ylab="Cumulative Proportion of Species",xlim=c(-.05,2200),

main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1)

dev.off()

## ecdf plot of all facilities by species 

png(file="facility.all.crithab.ecdf.png",width=768,height=768,pointsize=24)

par(mfrow=c(1,1))

plot(ecdf(facs$crithab[facs$crithab>0]),verticals=TRUE,xlab="Critical Habitat 

Overlaps per Facility",ylab="Cumulative Proportion of Facilities",xlim=c(-

.05,10),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1)

dev.off()

## ecdf plot of all species by facility

png(file="species.all.crithab.ecdf.png",width=768,height=768,pointsize=24)

par(mfrow=c(1,1))

plot(ecdf(spp$crithab[spp$crithab>0]),verticals=TRUE,xlab="Facility Overlaps 

per Species' Critical Habitat",ylab="Cumulative Proportion of Species",xlim=c(-

.05,60),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1)

dev.off()

## ecdf plot of all species subsets by facility

png(file="species.ecdf.png",width=1152,height=768,pointsize=24)

par(mfrow=c(2,3))
par(oma=c(5,5,5,5)); par(mar=c(0.25,0.25,0.25,0.25))

plot(ecdf(subset(spp,spp$group=="m")$facilities),verticals=TRUE,xlab="Facilitie

s per Impacted Species",ylab="Cumulative Proportion of Species",xlim=c(-

.05,105),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,ylim=c(0,1.1), 

xaxt ="n")

mtext("Freshwater Mussels (53)",line=-1.5,family="serif")

axis(3,family="serif");

mtext("Proportion of Species",side=2,line=2.5,cex=1.2,family="serif",at=-.08)

plot(ecdf(subset(spp,spp$group=="a")$facilities),verticals=TRUE,xlab="Facilitie

s per Impacted Species",ylab="Cumulative Proportion of Species",xlim=c(-

.05,105),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,ylim=c(0,1.1), 

xaxt = "n", yaxt = "n")

mtext("Anadromous Fish (12)",line=-1.5,family="serif")

axis(3,family="serif"); axis(4,family="serif")

plot.new()

plot(ecdf(subset(spp,spp$group=="s")$facilities),verticals=TRUE,xlab="Facilitie

s per Impacted Species",ylab="Cumulative Proportion of Species",xlim=c(-

.05,105),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,ylim=c(0,1.1))

mtext("Snails (7)",line=-1.5,family="serif")

plot(ecdf(subset(spp,spp$group=="t")$facilities),verticals=TRUE,xlab="Facilitie

s per Impacted Species",ylab="Cumulative Proportion of Species",xlim=c(-

.05,105),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,ylim=c(0,1.1),

yaxt="n")

mtext("Sea Turtles (6)",line=-1.5,family="serif")

mtext("Facilities per Species",side=1,line=2.5,cex=1.2,family="serif", at = 50)

plot(ecdf(subset(spp,spp$group=="o")$facilities),verticals=TRUE,xlab="Facilitie

s per Impacted Species",ylab="Cumulative Proportion of Species",xlim=c(-

.05,8),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,ylim=c(0,1.1),ya

xt="n")

mtext("Freshwater Fish* (21)",line=-1.5,family="serif")

axis(4,family="serif")

dev.off()

## ecdf plots of all species within regions

png(file="regions.ecdf.png",width=1024,height=1024,pointsize=24)

facs$regs <- as.factor(facs$regs)

regs=levels(facs$regs)

regs[regs=="Inland"]="Inland*"

regs[regs=="West Coast"]="California"

par(mfrow=c(3,3))

par(cex.axis=1.3)

par(oma=c(5,5,5,5)); par(mar=c(0,0,0.25,0.25))

reg.count=c(21, 50, 22, 566, 46, 21, 12)

table(facs$regs)
for(i in c(1,6,5,7,3,2,4)){

if(i== 5 | i==3) plot(1, type="n", axes=F, xlab="", ylab="")

if (i == 1 | i == 5 | i == 3) 

plot(ecdf(subset(facs,facs$regs==levels(facs$regs)[i])$all),verticals=TRUE,xlab

="Number of Species per Facility",ylab="Cumulative Proportion of 

Facilities",xlim=c(-

.05,9),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,yaxt="n",xaxt="n

",ylim=c(0,1.1))

if (i == 6 | i == 7 | i == 2) 

plot(ecdf(subset(facs,facs$regs==levels(facs$regs)[i])$all),verticals=TRUE,xlab

="Number of Species per Facility",ylab="Cumulative Proportion of 

Facilities",xlim=c(-

.05,9),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,yaxt="n",xaxt="n

",ylim=c(0,1.1))

#if(i==3)plot(0,0,yaxt="n",xaxt="n",ylim=c(-2,-1),xlim=c(-4,-2),bty="n")

if(i==4) 

plot(ecdf(subset(facs,facs$regs==levels(facs$regs)[i])$all),verticals=TRUE,xlab

="Number of Species per Facility",ylab="Cumulative Proportion of 

Facilities",xlim=c(-

.05,30),main="",family="serif",cex.lab=1.2,cex=1.1,cex.axis=1.1,yaxt="n",xaxt="

n",ylim=c(0,1.1))

mtext(paste(regs[i]," (",reg.count[i],")",sep=""),line=-

1.3,family="serif")

if(i == 4) axis(1,family="serif",cex=1.3)

if(i == 3 | i == 2) axis(1,family="serif",cex=1.3)

if(i==1 | i == 5 | i ==3) 

axis(2,at=c(0,0.2,0.4,0.6,0.8,1.0),labels=TRUE,family="serif",cex=1.3)

if(i==6 | i == 7) 

axis(4,at=c(0,0.2,0.4,0.6,0.8,1.0),labels=TRUE,family="serif",cex=1.3)

if(i== 5) mtext("Proportion of 

Facilities",side=2,line=2.5,cex=1.2,family="serif")

if(i==2) mtext("Species per 

Facility",side=1,line=2.5,cex=1.2,family="serif")

}

dev.off()