Using the code below, I am able to produce an output, however, the start_time when plotted is 06:00 instead of 09:00, and the end_time is 12:00, instead of 15:01. I would appreciate knowing where I am going wrong.
Many thanks
Lara
library(lubridate)
library(tidyverse)
library(reshape2)
library(dplyr)
library(ggplot2)
library(lubridate)
Read the CSV file and assign it to a variable (e.g., box1077102745)
box1077102745 <- read.csv("C:/Users/ltookey/OneDrive - Massey University/03.0_PhD/DATA/IEQ_Skomobo/WMK/R11/box1077102745.csv")
Convert "Time" column to POSIXct
box1077102745$Time <- as.POSIXct(box1077102745$Time, format = "%Y-%m-%d %H:%M:%S", tz = "Pacific/Auckland")
Specify the week and time range
start_date <- as.POSIXct("2023-09-04 09:00:00", tz = "Pacific/Auckland")
end_date <- start_date + 5 * 24 * 60 * 60 # 5 SCHOOL days in seconds
end_date <- as.POSIXct(end_date, tz = "Pacific/Auckland")
start_time <- hms("09:00:00")
end_time <- hms("15:01:00")
Create intervals for the entire week and specific time range
week_interval <- interval(start_date, end_date)
time_range_interval <- interval(start_date + start_time, start_date + end_time)
Filter data for the specific week and time range
filtered_data <- box1077102745 %>%
filter(
ymd_hms(Time) >= start_date,
ymd_hms(Time) <= end_date,
ymd_hms(Time) >= start_date + start_time,
ymd_hms(Time) <= start_date + end_time
)
str(filtered_data)
Reshape filtered data using melt
plot_data <- melt(filtered_data, id.vars = 'Time', measure.vars = c('Temp', 'Humid', 'CO2'))
Create a multivariate time series plot for the selected week and time range
ggplot(plot_data, aes(x = Time, y = value, color = variable)) +
geom_line() +
facet_wrap(~variable, scales = "free_y", ncol = 1) +
labs(title = "Multivariate Time Series Plot of IEQ Data (Selected Week and Time Range)",
x = "Time",
y = "Value") +
scale_color_manual(values = c("Temp" = "blue", "Humid" = "green", "CO2" = "red")) +
theme_minimal()