library(ggplot2)
ecan <- read.csv('RangioraWinter2016.csv',stringsAsFactors=FALSE)
names(ecan) <- c('date','time','wind.speed','wind.dir','wind.dir.std','wind.speed.std',
'wind.max','co','temp.ground','temp.2m','temp.6m','pm10',
'pm2.5','pm.course')
ecan$date <- as.POSIXct(ecan$date,format = '%m/%d/%Y %H:%M', tz='Etc/GMT-12')
ecan <- ecan[,c('date','wind.speed')]
# Split into noon-noon periods
date.lt <- as.POSIXlt(ecan$date)
# Only consider the range of July-November
noons <- ecan[which(date.lt$hour==12 & date.lt$min==0 & date.lt$mon>5 &
date.lt$mon<10),'date']
day.winds <- data.frame(date=noons[1], mean.wind.speed=NA, sd.wind.speed=NA)
for (i in 2:length(noons)) {
day.data <- ecan[which(noons[i-1] < ecan$date & ecan$date < noons[i]), ]
day.winds[i, 'mean.wind.speed'] <- mean(day.data$wind.speed, na.rm=TRUE)
day.winds[i, 'sd.wind.speed'] <- sd(day.data$wind.speed, na.rm=TRUE)
day.winds[i, 'date'] <- day.data$date[1]
}
# Print 20 days with least wind
sorted.day.winds <- day.winds[order(day.winds$mean.wind.speed), ]
print(sorted.day.winds[1:20, ])
## date mean.wind.speed sd.wind.speed
## 41 2016-08-09 12:10:00 0.7469930 0.6746768
## 12 2016-07-11 12:10:00 0.8121678 0.4292954
## 4 2016-07-03 12:10:00 0.8669231 0.5692152
## 60 2016-08-28 12:10:00 0.9043357 0.7380432
## 9 2016-07-08 12:10:00 0.9123776 0.6646263
## 32 2016-07-31 12:10:00 0.9543357 0.9068826
## 6 2016-07-05 12:10:00 0.9628671 0.5330864
## 46 2016-08-14 12:10:00 1.0255944 0.7692255
## 3 2016-07-02 12:10:00 1.0942657 0.5050986
## 74 2016-09-11 12:10:00 1.1120896 0.6202996
## 85 2016-09-22 12:10:00 1.1234965 0.7679168
## 7 2016-07-06 12:10:00 1.1797902 0.6217643
## 62 2016-08-30 12:10:00 1.1915385 0.8660899
## 42 2016-08-10 12:10:00 1.2072727 1.0703245
## 52 2016-08-20 12:10:00 1.2468531 1.0231885
## 16 2016-07-15 12:10:00 1.2871329 0.7521637
## 108 2016-10-15 12:10:00 1.2962937 0.7449149
## 114 2016-10-21 12:10:00 1.2979720 1.1698462
## 11 2016-07-10 12:10:00 1.3042657 0.5621406
## 20 2016-07-19 12:10:00 1.3066434 0.7796342
# Add sd lines
plot.data <- data.frame(date=day.winds$date, wind.speed=day.winds$mean.wind.speed,
label=rep('mean', nrow(day.winds)))
plot.plus <- data.frame(date=day.winds$date, wind.speed=
day.winds$mean.wind.speed + day.winds$sd.wind.speed,
label=rep('mean+sd', nrow(day.winds)))
plot.minus <- data.frame(date=day.winds$date, wind.speed=
day.winds$mean.wind.speed - day.winds$sd.wind.speed,
label=rep('mean-sd', nrow(day.winds)))
plot.data <- rbind(plot.plus, plot.data)
plot.data <- rbind(plot.data, plot.minus)
# Plot wind over time
ggplot(plot.data) +
geom_line(aes(date, wind.speed, colour=label))
## Warning: Removed 3 rows containing missing values (geom_path).
