Skip to content

Instantly share code, notes, and snippets.

@jasonknebel
Created December 10, 2012 02:07
Show Gist options
  • Save jasonknebel/4247984 to your computer and use it in GitHub Desktop.
Save jasonknebel/4247984 to your computer and use it in GitHub Desktop.
setwd('~/Documents/zooplankton')
data = read.csv("Env_x_Zoop use this data set _.csv")
chla = data[,3]
conduct = data[,4]
logTotal = data[,6]
richness = data[,7]
sumZoo = data[,8]
for(i in 9:34){sumZoo = sumZoo + data[,i]}
comm_conduct = data[1:13,4]
res_conduct = data[14:28,4]
#############################
#1a
plot(conduct, chla, xlab="Salinity (as measured by conductivity) (µS)",
ylab="Chlorophyll a", main="Salinity and the response of Chlorophyll a")
dev.copy(png,'1a.chla_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#1b
plot(conduct, sumZoo, xlab="Salinity (as measured by conductivity) (µS)",
ylab="Total Zooplankton Abundance", main="Salinity and the response of Zooplankton abundance")
dev.copy(png,'1b.total_zoo_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#1c
plot(conduct, richness, xlab="Salinity (as measured by conductivity) (µS)",
ylab="Richness", main="Conductivity vs Richness")
dev.copy(png,'1c.richness_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#############################
#2a
plot(conduct, chla, xlab="Salinity (as measured by conductivity) (µS)",
ylab="Chlorophyll a", main="Salinity and the response of Chlorophyll a")
lm_chla = lm(chla~conduct) #compute linear model (regression)
abline(lm_chla) #plot regression
lm_coef <- round(coef(lm_chla), 3) # extract coefficients
mtext(bquote(y == .(lm_coef[2])*x + .(lm_coef[1])), adj=1, padj=0) # display equation
dev.copy(png,'2a.lm_chla_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#2b
plot(conduct, logTotal, xlab="Salinity (as measured by conductivity) (µS)",
ylab="logTotal", main="Salinity and the response of logTotal")
lm_logTotal = lm(logTotal~conduct)
abline(lm_logTotal)
lm_coef <- round(coef(lm_chla), 3)
mtext(bquote(y == .(lm_coef[2])*x + .(lm_coef[1])), adj=1, padj=0)
dev.copy(png,'2b.lm_logTotal_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#2c
plot(conduct, richness, xlab="Salinity (as measured by conductivity) (µS)",
ylab="Richness", main="Salinity and the response of Richness")
lm_richness = lm(richness~conduct)
abline(lm_richness)
lm_coef <- round(coef(lm_chla), 3)
mtext(bquote(y == .(lm_coef[2])*x + .(lm_coef[1])), adj=1, padj=0)
dev.copy(png,'2c.lm_richness_vs_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#############################
#3a
g_range <- range(0, comm_conduct, res_conduct) #calculate y-range
plot(res_conduct, type="o", col="blue", ylim=g_range, axes=FALSE, ann=FALSE)
axis(1, at=1:16)
axis(2, las=1, at=200*0:g_range[2])
box()
lines(comm_conduct, type="o", pch=22, lty=2, col="red")
title(main="Salinity of Commercial and Residental Ponds")
title(xlab="Pond Number")
title(ylab="Salinity (as measured by conductivity) (µS)")
legend(1, g_range[2], c("Residential","Commercial"), cex=0.8, col=c("blue","red"),
pch=21:22, lty=1:2);
dev.copy(png,'3a.commercial_and_residential_conductivity.png', width = 514, height = 398, units = "px")
dev.off()
#############################
#4a
i=0;
shannon = 1:29;
for(i in 1:29){
shannon[i]=0;
for(j in 8:34){
if(data[i,j]>0) shannon[i] = shannon[i] - (data[i,j]/sumZoo[i])*log(data[i,j]/sumZoo[i])
}
}
plot(1:29, shannon, xlab = "Pond Number", ylab = "Shannon Index", main = "Pond Diversity")
dev.copy(png,'4a.shannon_index.png', width = 514, height = 398, units = "px")
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment