Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sumfile <- read.csv('https://dl.dropbox.com/s/zy6b5mjcu7uteof/data_all_PAR_max.csv')
- codename = "EXEM"
- descriptor = "max"
- radtype = "PAR"
- totYrs = c(1997:2015)
- ylbl = expression("PAR " ~ (mu ~ mol ~ photons ~ m^{-2} ~ s^{-1}))
- clr = "blue"
- group <- melt(sumfile, id.vars = 'date', variable.name = 'series')
- setnames(group, old = c('date','series','value'), new = c('Date','Year',radtype))
- group$Date <- as.Date(group$Date)
- # group <- na.omit(group) # uncommenting resolves error!
- o <- order(group$Date)
- lo <- loess(PAR ~ as.numeric(Date), span = 0.25, data=group)
- plot(group$Date,group$PAR,pch=19,cex=0.1, col=clr,
- xlab ="Date",
- ylab = ylbl,
- main = paste('Loess curve for', descriptor, radtype, 'from', min(totYrs), 'to',
- max(totYrs), 'nmeasured at', codename, 'met',sep=' '))
- lines(group$Date[o], lo$fitted[o], col='red', lwd=1)
- points(group$Date[o], lo$fitted[o], col='red', lwd=1)
- for (i in totYrs) {
- tryCatch({
- yval <- paste(radtype, i, descriptor,sep='_')
- sumfile$date <- as.Date(sumfile$date)
- lo_ <- eval(parse(text = paste("loess(", yval, "~ as.numeric(date),
- span = 0.25, data=sumfile)")))
- oo <- order(sumfile$date)
- plot(sumfile$date, eval(parse(text = paste("sumfile$",yval))),
- pch=19,cex=0.1, col=clr,
- xlab ="Date",
- ylab = ylbl,
- main = paste('Loess curve for', descriptor, radtype, 'measured atn',
- codename, 'met during', i, '/', i+1, 'field season',sep=' '))
- lines(sumfile$date[oo], lo_$fitted[oo], col='red', lwd=1)
- }, error=function(e){print("One or more years was not plotted because there was no data")})
- }
- sumfile$date <- as.Date(sumfile$date)
- no_na <- na.omit(subset(sumfile, select=c(date,PAR_2013_max)))
- lo13 <- loess(PAR_2013_max ~ as.numeric(date), span = 0.25, data=no_na)
- oo <- order(sumfile$date)
- plot(sumfile$date, sumfile$PAR_2013_max)
- lines(sumfile$date[oo], lo13$fitted[oo], col='red', lwd=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement