## read in the file and attach variable names benthic <- read.table("Benthicfluxes.txt", header=TRUE) # read in file + header = TRUE to inform that first line contains variable names benthic attach(benthic) # attach variable names, so R recognizes them #load package for re-arranging datasets library(plyr) library(tidyr) library(car) #load packages for plotting library(ggplot2) ## calculate the average counts for each biotic component (zoo, phyto and macro) per location mean.zooplankton=tapply(zooplankton, location, mean) # special function tapply() to calculate mean values mean.phytoplankton=tapply(phytoplankton, location, mean) mean.macrobenthos=tapply(macrobenthos, location, mean) ## explore the data using graphs (! more advanced plots can be used with ggplot function) # relationships between biotic components (regression, all continuous) plot(zooplankton~phytoplankton) abline(lm(zooplankton~phytoplankton, data=benthic), col="red") # add regression line plot(macrobenthos~zooplankton) abline(lm(macrobenthos~zooplankton, data=benthic), col="red") plot(macrobenthos~phytoplankton) abline(lm(macrobenthos~phytoplankton, data=benthic), col="red") # densities per location (discrete independent variable, so boxplots) plot(zooplankton ~ location) plot(phytoplankton ~ location) plot(macrobenthos ~ location) # macrofauna densities per location and the influence of predators library(lattice) bwplot(macrobenthos ~ predators | location) # plot for two different variables detach(benthic)