+ Show code- Hide code
## This is code is Op_en2959/temperatures [[Outdoor air temperature in Finland]]
library(OpasnetUtils)
ta <- opbase.data("Op_en2959", subset = "Vantaa") # [[Outdoor air temperature in Finland]]
levels(ta$Year)[as.numeric(as.character(levels(ta$Year))) < 2015] <- "2012"
ta$Date <- as.POSIXct(paste(ta$Year, ta$Month, ta$Day, sep = "-"))
days <- aggregate(ta[c(
"Temperature" # We only need temperature, but it is easy to take any other variable as well.
# "Relative_humidity",
# "Wind_direction",
# "Wind_speed",
# "Direct_normal_solar_radiation",
# "Diffuse_horisontal_radiation",
# "Result" # Global_horizontal_radiation
)], ta[c("Date", "Year")], FUN = mean)
colnames(days)[colnames(days) == "Temperature"] <- "Result"
days$Temperature <- cut(days$Result, breaks = seq(-30, 33, 3))
temperatures <- Ovariable("temperatures", data = aggregate(days["Result"], days[c("Temperature", "Year")], FUN = mean))
temperdays <- Ovariable("temperdays", data = aggregate(days["Result"], days[c("Temperature", "Year")], FUN = length))
years = data.frame(Time = 1985:2070, Year = c(rep("2012", 36), rep("2030", 20), rep("2050", 30)))
temperatures@data <- merge(temperatures@data, years)
temperatures@data$Year <- NULL
temperdays@data <- merge(temperdays@data, years)
temperdays@data$Year <- NULL
objects.store(temperatures, temperdays)
cat("Objects temperatures, temperdays stored.\n")
#ggplot(hours, aes(x = Time, y = Result))+geom_line() + geom_point(data = days, aes(x = Date, y = Result, colour = "Daily mean", size = 2))
#ggplot(hours, aes(x = Time, y = Result))+geom_point()
| |