I'm currently attempting to create a scatterplot with date related summed values. This same procedure has worked for displaying yearly values but does not seem to work.
This is the current code for the date related plot
benthos = WE_Benthos_Cleaned_mg_2
#Remove NA rows and make NA values that should be 0 into 0
benthos = benthos[!benthos$lakeID=='NA',]
benthos$Drymassweight_Biomass[is.na(benthos$Drymassweight_Biomass)] = 0
#First, lets add all the insect biomass together per station and sampling event
benSum = ddply(benthos, c("lakeID","date","stationID","depth","repID"), summarise,
sumDM_mg = sum(Drymassweight_Biomass,na.rm=T))
#To look at general patterns in biomass, we are going to get a mean value for the different habitats for each year
benMeandate = ddply(benSum, c("lakeID","depth","date"), summarise,
N = length(sumDM_mg),
meanDM = mean(sumDM_mg,na.rm=T),
sd = sd(sumDM_mg,na.rm=T),
SE = (sd / sqrt(N)))
#Add confidence interval columns
benMeandate$Upper2SE = benMeandate$meanDM+1.96*benMeandate$SE
benMeandate$Lower2SE = benMeandate$meanDM-1.96*benMeandate$SE
#Jitter
benMeandate$date[benMeandate$lakeID=="WE2"] = benMeandate$year[benMeandate$lakeID=="WE2"] + 0.05
benMeandate$date[benMeandate$lakeID=="WE1"] = benMeandate$year[benMeandate$lakeID=="WE1"] - 0.05
#Plot mean biomass/year - Hypo
benMeandate_hypo = benMeandate[benMeandate$depth=='hypolimnion',]
plot(benMeandate_hypo$date,benMeandate_hypo$meanDM,col=ifelse(benMeandate_hypo$lakeID=="WE2",'black','gray'),
pch=ifelse(benMeandate_hypo$lakeID=="WE2",21,24),bg=ifelse(benMeandate_hypo$lakeID=="WE2","black","gray"),ylim=c(-0.04,0.6),xlim=c(2016,2021),
ylab = "Mean Biomass (mg-AFDM)",xlab="Year",xaxt="n")
abline(v=2018.5,lty=2)
axis(1, xaxp=c(2017, 2020, 3), las=1)
arrows(benMeandate_hypo$date,benMeandate_hypo$Lower2SE,benMeandate_hypo$date,benMeandate_hypo$Upper2SE, code=3, length=0.02, angle = 90,
col=ifelse(benMeandate_hypo$lakeID=="WE2",'black','gray'))
And here is a portion of the data
lakeID | depth | year | N | meanDM |
---|---|---|---|---|
WE1 | hypolimnion | 2016.95 | 6 | 0.002262546 |
WE1 | hypolimnion | 2017.95 | 11 | 0.032788214 |
WE1 | hypolimnion | 2018.95 | 5 | 0.049376644 |
WE1 | hypolimnion | 2019.95 | 13 | 0.286644714 |
WE2 | hypolimnion | 2017.05 | 3 | 0.016292398 |
WE2 | hypolimnion | 2018.05 | 10 | 0.059015917 |
WE2 | hypolimnion | 2019.05 | 5 | 0.131525626 |
WE2 | hypolimnion | 2020.05 | 11 | 0.014298989 |
I'm using the following packages
library(readxl) library(plyr) library(lubridate)
I'm sure i'm missing something here