Kelompok 10:
1. Fathatia Cholida Syifa (5003231070)
2. Suhanur Haliza (5003231078)
3. Diazty Ifta Padvani (5003231171)
4. Pingky Oktania Tata Sefina (5003231184)
library(dplyr)
library(lubridate)
library(ggplot2)
library(tidyr)
library(scales)
library(forecast)
WiFi Data
wifi=read.csv('C:/Users/Lenovo/Downloads/wifi.csv')
head(wifi)
colnames(wifi)
[1] "time" "Event.Time" "Associated.Client.Count" "Authenticated.Client.Count"
[5] "Uni" "Building" "Floor"
str(wifi)
'data.frame': 1883844 obs. of 7 variables:
$ time : chr "2020-02-01 00:02:12" "2020-02-01 00:02:12" "2020-02-01 00:02:12" "2020-02-01 00:02:12" ...
$ Event.Time : chr "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" ...
$ Associated.Client.Count : int 184 6 18 23 45 16 32 6 73 5 ...
$ Authenticated.Client.Count: int 182 6 18 23 45 16 32 6 73 5 ...
$ Uni : chr "Lancaster University " "Lancaster University " "Lancaster University " "Lancaster University " ...
$ Building : chr " Graduate College " " Management School " " SW hse 32-33 " " SW hse 29 " ...
$ Floor : chr " A Floor" " C Floor" " D Floor" " B floor" ...
wifi$time=as.POSIXct(wifi$time)
str(wifi)
'data.frame': 1883844 obs. of 7 variables:
$ time : POSIXct, format: "2020-02-01 00:02:12" "2020-02-01 00:02:12" "2020-02-01 00:02:12" "2020-02-01 00:02:12" ...
$ Event.Time : chr "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" "Sat Feb 01 00:02:12 UTC 2020" ...
$ Associated.Client.Count : int 184 6 18 23 45 16 32 6 73 5 ...
$ Authenticated.Client.Count: int 182 6 18 23 45 16 32 6 73 5 ...
$ Uni : chr "Lancaster University " "Lancaster University " "Lancaster University " "Lancaster University " ...
$ Building : chr " Graduate College " " Management School " " SW hse 32-33 " " SW hse 29 " ...
$ Floor : chr " A Floor" " C Floor" " D Floor" " B floor" ...
unique(wifi$Building)
[1] " Graduate College " " Management School " " SW hse 32-33 "
[4] " SW hse 29 " " Furness outer " " Slaidburn House (LUSU) "
[7] " SW hse 34 " " Bowland hall " " Fylde "
[10] " SW hse 55-56 " " SW hse 40-42 " " Bowland Twr (Old Bowland Annexe) "
[13] " Pendle " " Faraday and cTAP " " Institute for Advanced Studies "
[16] " University House " " SW hse 53-54 " " Engineering "
[19] " Field Station " " SW hse 36 " " Infolab "
[22] " SW hse 21-23 " " LICA " " FU Hse 71-74 "
[25] " Grizedale " " Charles Carter " " Furness "
[28] " SW hse 43-45 " " SW hse 12-16 " " Bowland Main "
[31] " SW hse 35 " " Human Resources " " County "
[34] " FY Hse 65-70 " " Barker House Farm " " SW hse 27-28 "
[37] " Bowland Annexe " " John Creed " " grize-res "
[40] " SW hse 24-26 " " SW hse 20 " " Ruskin Library "
[43] " County South/Cartmel " " Library " " Conference Centre "
[46] " Postgrad Stats (PSC) " " Bowland North " " George Fox "
[49] " Hse 75 77 " " Bailrigg House " " Sports Centre "
[52] " SW hse 30-31 " " Bowland Ash " " Alex Square "
[55] " LEC " " MDC " " ISS Building "
[58] " Chaplaincy Centre " " CETAD " " SW hse 50-52 "
[61] " SW hse 17-19 " " Central Workshops " " SW hse 46-49 "
[64] " SW hse 39 " " Science and technology " " Whewell "
[67] " SW hse 37-38 " " Lonsdale College (SW) " " Physics "
[70] " County Field " " Great Hall " " SW hse-158-179 "
[73] " Preschool " " Reception " " Hazelrigg "
[76] " Energy Centre "
wifi=wifi[wifi$Building == " Library ",]
head(wifi)
wifi=wifi[,c('time','Associated.Client.Count')]
head(wifi)
wifi=wifi %>%
mutate(time = floor_date(time, "10 minutes")) %>%
group_by(time) %>%
summarise(
occupancy = mean(`Associated.Client.Count`, na.rm = TRUE),
.groups = "drop"
)
head(wifi)
colSums(is.na(wifi))
time occupancy
0 0
sum(duplicated(wifi))
[1] 0
dim(wifi)
[1] 3683 2
Library Energy Data
library1=read.csv('C:/Users/Lenovo/Downloads/library1.csv')
library2=read.csv('C:/Users/Lenovo/Downloads/library2.csv')
library3=read.csv('C:/Users/Lenovo/Downloads/library3.csv')
head(library1)
str(library1)
'data.frame': 18864 obs. of 6 variables:
$ ts : chr "2020-01-01 00:00:00" "2020-01-01 00:10:00" "2020-01-01 00:20:00" "2020-01-01 00:30:00" ...
$ name : chr "MC065-L01/M9R2048" "MC065-L01/M9R2048" "MC065-L01/M9R2048" "MC065-L01/M9R2048" ...
$ reading : num 1489442 1489449 1489456 1489464 1489471 ...
$ units : chr "KWh" "KWh" "KWh" "KWh" ...
$ cumulative: num 1489442 1489449 1489456 1489464 1489471 ...
$ rate : num NA 7 7 8 7 8 7 8 7 8 ...
library1$ts=as.POSIXct(library1$ts)
library2$ts=as.POSIXct(library2$ts)
library3$ts=as.POSIXct(library3$ts)
str(library1)
'data.frame': 18864 obs. of 6 variables:
$ ts : POSIXct, format: "2020-01-01 00:00:00" "2020-01-01 00:10:00" "2020-01-01 00:20:00" "2020-01-01 00:30:00" ...
$ name : chr "MC065-L01/M9R2048" "MC065-L01/M9R2048" "MC065-L01/M9R2048" "MC065-L01/M9R2048" ...
$ reading : num 1489442 1489449 1489456 1489464 1489471 ...
$ units : chr "KWh" "KWh" "KWh" "KWh" ...
$ cumulative: num 1489442 1489449 1489456 1489464 1489471 ...
$ rate : num NA 7 7 8 7 8 7 8 7 8 ...
colSums(is.na(library1))
ts name reading units cumulative rate
0 0 3041 0 3041 3047
colSums(is.na(library2))
ts name reading units cumulative rate
0 0 3041 0 3041 3047
colSums(is.na(library3))
ts name reading units cumulative rate
0 0 3041 0 3041 3047
library1$rate[is.na(library1$rate)]=mean(library1$rate[1:144],na.rm = TRUE)
library2$rate[is.na(library2$rate)]=mean(library2$rate[1:144],na.rm = TRUE)
library3$rate[is.na(library3$rate)]=mean(library3$rate[1:144],na.rm = TRUE)
library_all=merge(library1,library2,by='ts',all = TRUE)
library_all=merge(library_all,library3,by='ts',all = TRUE)
head(library_all)
library_all$energy_consumption<-library_all$rate.x + library_all$rate.y + library_all$rate
head(library_all)
names(library_all)[names(library_all)=='ts']='time'
sum(duplicated(library_all))
[1] 0
df=merge(wifi,library_all,by='time',all.x = TRUE)
df=df[,c('time','occupancy','energy_consumption')]
head(df)
dim(df)
[1] 3683 3
Time Series Plot: Occupancy & Energy Consumption
ggplot(df, aes(x = time)) +
geom_line(aes(y = occupancy, color = "Occupancy")) +
geom_line(aes(y = energy_consumption, color = "Energy Consumption")) +
scale_color_manual(values = c("Occupancy" = "blue", "Energy Consumption" = "red")) +
labs(title = "Time Series of Occupancy and Energy Consumption",
x = "Time",
y = "Value",
color = "Legend") +
theme_minimal() +
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5))
Scatter Plot: Occupancy vs Energy Consumption
ggplot(df, aes(x = occupancy, y = energy_consumption)) +
geom_point(alpha = 0.5, color = "blue") +
labs(title = "Scatter Plot: Occupancy vs Energy Consumption",
x = "Occupancy (Number of Clients)",
y = "Energy Consumption (kWh)") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
Daily Profiles (24h)
Occupancy
df = df %>%
mutate(
date = as.Date(time),
hour = hour(time) + minute(time)/60
)
ggplot(df, aes(x = hour, y = occupancy, group = date)) +
geom_line(alpha = 0.1, color = "blue") +
geom_line(
data = df %>% group_by(hour) %>% summarise(avg_occ = mean(occupancy, na.rm=TRUE)),
aes(x = hour, y = avg_occ, group = 1),
color = "blue", size = 1.2
) +
labs(
title = "Daily Profiles of Occupancy",
x = "Hour of Day",
y = "Occupancy"
) +
scale_x_continuous(breaks = seq(0, 24, 1)) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
df = df %>%
mutate(
date = as.Date(time),
hour_decimal = hour(time) + minute(time)/60
)
ggplot(df, aes(x = hour_decimal, y = occupancy, group = date)) +
geom_line(alpha = 0.1, color = "blue") +
geom_line(
data = df %>% group_by(hour_decimal) %>% summarise(avg_occ = mean(occupancy, na.rm=TRUE)),
aes(x = hour_decimal, y = avg_occ, group = 1),
color = "blue", size = 1.2
) +
labs(
title = "Daily Profiles of Occupancy",
x = "Time of Day",
y = "Occupancy"
) +
scale_x_continuous(
breaks = seq(0, 24, by = 1/6),
labels = function(x) sprintf("%02d:%02d", floor(x), round((x %% 1) * 60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Energy Consumption
ggplot(df, aes(x = hour, y = energy_consumption, group = date)) +
geom_line(alpha = 0.1, color = "red") +
geom_line(
data = df %>% group_by(hour) %>% summarise(avg_energy = mean(energy_consumption, na.rm=TRUE)),
aes(x = hour, y = avg_energy, group = 1),
color = "red", size = 1.2
) +
labs(
title = "Daily Profiles of Energy Consumption",
x = "Hour of Day",
y = "Energy Consumption"
) +
scale_x_continuous(breaks = seq(0, 24, 1)) +
theme_minimal()+
theme(plot.title = element_text(hjust = 0.5))
ggplot(df, aes(x = hour_decimal, y = energy_consumption, group = date)) +
geom_line(alpha = 0.1, color = "red") +
geom_line(
data = df %>% group_by(hour_decimal) %>% summarise(avg_energy = mean(energy_consumption, na.rm=TRUE)),
aes(x = hour_decimal, y = avg_energy, group = 1),
color = "red", size = 1.2
) +
labs(
title = "Daily Profiles of Energy Consumption",
x = "Time of Day",
y = "Energy Consumption"
) +
scale_x_continuous(
breaks = seq(0, 24, by = 1/6),
labels = function(x) sprintf("%02d:%02d", floor(x), round((x %% 1) * 60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Peak Hour Occupancy
df_avg_hour <- df %>%
group_by(hour_label = format(time, "%H:00")) %>%
summarise(mean_occupancy = base::mean(occupancy, na.rm = TRUE), .groups = "drop") %>%
arrange(hour_label)
peak_hours <- dplyr::arrange(df_avg_hour, desc(mean_occupancy))
head(peak_hours)
ggplot(df_avg_hour, aes(x = hour_label, y = mean_occupancy, group = 1)) +
geom_line(color = "blue", linewidth = 1) +
geom_point(color = "red", size = 3) +
labs(
title = "Rata-rata Occupancy per Jam",
x = "Jam (00:00–23:00)",
y = "Rata-rata Occupancy"
) +
theme_minimal(base_size = 14) +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5))
Correlation
corr=cor(electricity$mean_client_count, electricity$total_electricity)
corr
[1] 0.8782117
Time Series Regression
df_reg <- df %>%
arrange(time) %>%
mutate(t = row_number(),
hour = factor(format(time, "%H")))
model_tslm <- lm(energy_consumption ~ occupancy + t + hour, data = df_reg)
summary(model_tslm)
Call:
lm(formula = energy_consumption ~ occupancy + t + hour, data = df_reg)
Residuals:
Min 1Q Median 3Q Max
-55.416 -8.208 0.084 8.520 55.706
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.162e+02 1.097e+00 105.958 < 2e-16 ***
occupancy 1.763e-01 3.346e-03 52.688 < 2e-16 ***
t 9.812e-04 2.033e-04 4.825 1.46e-06 ***
hour01 -7.731e+00 1.463e+00 -5.286 1.32e-07 ***
hour02 -1.517e+01 1.463e+00 -10.367 < 2e-16 ***
hour03 -2.251e+01 1.465e+00 -15.368 < 2e-16 ***
hour04 -3.260e+01 1.465e+00 -22.263 < 2e-16 ***
hour05 -4.356e+01 1.465e+00 -29.738 < 2e-16 ***
hour06 -4.390e+01 1.466e+00 -29.952 < 2e-16 ***
hour07 -3.567e+01 1.465e+00 -24.346 < 2e-16 ***
hour08 -1.530e+01 1.462e+00 -10.468 < 2e-16 ***
hour09 -1.983e+00 1.468e+00 -1.351 0.177
hour10 7.604e+00 1.538e+00 4.945 7.97e-07 ***
hour11 8.377e+00 1.637e+00 5.117 3.26e-07 ***
hour12 1.191e+01 1.700e+00 7.006 2.91e-12 ***
hour13 1.155e+01 1.758e+00 6.568 5.81e-11 ***
hour14 8.922e+00 1.819e+00 4.905 9.75e-07 ***
hour15 9.191e+00 1.845e+00 4.982 6.57e-07 ***
hour16 1.284e+01 1.796e+00 7.147 1.06e-12 ***
hour17 1.907e+01 1.700e+00 11.215 < 2e-16 ***
hour18 2.014e+01 1.611e+00 12.504 < 2e-16 ***
hour19 2.170e+01 1.562e+00 13.889 < 2e-16 ***
hour20 2.130e+01 1.530e+00 13.924 < 2e-16 ***
hour21 1.992e+01 1.509e+00 13.202 < 2e-16 ***
hour22 1.912e+01 1.490e+00 12.832 < 2e-16 ***
hour23 1.143e+01 1.479e+00 7.726 1.42e-14 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 12.91 on 3657 degrees of freedom
Multiple R-squared: 0.9133, Adjusted R-squared: 0.9127
F-statistic: 1541 on 25 and 3657 DF, p-value: < 2.2e-16
Time Series Plot
df$fitted <- fitted(model_tslm)
ggplot(df, aes(x = time)) +
geom_line(aes(y = energy_consumption, color = "Observed"), linewidth = 0.8, alpha = 0.7) +
geom_line(aes(y = fitted, color = "Fitted"), linewidth = 1) +
scale_color_manual(values = c("Observed" = "blue", "Fitted" = "red")) +
labs(
title = "Time Series Regression",
x = "Time",
y = "Energy Consumption",
color = ""
) +
theme_minimal(base_size = 14)+
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5))
# Separate data into weekdays and weekends
df$time <- as_datetime(df$time)
df$day_of_week <- wday(df$time, week_start = 1) - 1
df_weekday <- df %>% filter(day_of_week < 5)
df_weekend <- df %>% filter(day_of_week >= 5)
df_weekday$time_of_day <- hms::as_hms(df_weekday$time)
df_weekend$time_of_day <- hms::as_hms(df_weekend$time)
Time Series Plot for Weekdays
ggplot(df_weekday, aes(x = time)) +
geom_line(aes(y = occupancy, color = "Occupancy")) +
geom_line(aes(y = energy_consumption, color = "Energy Consumption")) +
labs(title = "Time Series: Occupancy vs Energy Consumption (Weekdays)",
x = "Time",
y = "Value") +
scale_color_manual(values = c("Occupancy" = "blue", "Energy Consumption" = "red")) +
theme_minimal() +
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5))
Time Series Plot for Weekends
ggplot(df_weekend, aes(x = time)) +
geom_line(aes(y = occupancy, color = "Occupancy")) +
geom_line(aes(y = energy_consumption, color = "Energy Consumption")) +
labs(title = "Time Series: Occupancy vs Energy Consumption (Weekends)",
x = "Time",
y = "Value") +
scale_color_manual(values = c("Occupancy" = "blue", "Energy Consumption" = "red")) +
theme_minimal() +
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5))
Time Series Plot for Weekdays and Weekends
ggplot(df, aes(x = time)) +
geom_line(data = df_weekday, aes(y = occupancy, color = "Occupancy - Weekdays")) +
geom_line(data = df_weekday, aes(y = energy_consumption, color = "Energy Consumption - Weekdays")) +
geom_line(data = df_weekend, aes(y = occupancy, color = "Occupancy - Weekends"), linetype = "dashed") +
geom_line(data = df_weekend, aes(y = energy_consumption, color = "Energy Consumption - Weekends"), linetype = "dashed") +
labs(title = "Time Series: Occupancy vs Energy Consumption (Weekdays and Weekends)",
x = "Time",
y = "Value") +
scale_color_manual(values = c("Occupancy - Weekdays" = "blue", "Energy Consumption - Weekdays" = "red",
"Occupancy - Weekends" = "cyan", "Energy Consumption - Weekends" = "magenta")) +
theme_minimal() +
theme(legend.position = "bottom", plot.title = element_text(hjust = 0.5))
Scatter Plot for Weekdays
ggplot(df_weekday, aes(x = occupancy, y = energy_consumption)) +
geom_point(alpha = 0.4, color = "blue") +
labs(title = "Scatter Plot: Occupancy vs Energy (Weekdays)",
x = "Occupancy (WiFi Clients)",
y = "Energy Consumption") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
Scatter Plot for Weekends
ggplot(df_weekend, aes(x = occupancy, y = energy_consumption)) +
geom_point(alpha = 0.4, color = "red") +
labs(title = "Scatter Plot: Occupancy vs Energy (Weekends)",
x = "Occupancy (WiFi Clients)",
y = "Energy Consumption") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
Scatter Plot for Weekdays and Weekends
ggplot(df, aes(x = occupancy, y = energy_consumption, color = factor(day_of_week < 5))) +
geom_point(alpha = 0.4) +
scale_color_manual(values = c("TRUE" = "blue", "FALSE" = "red"), labels = c("Weekdays", "Weekends")) +
labs(title = "Scatter Plot: Occupancy vs Energy (Weekdays and Weekends)",
x = "Occupancy (WiFi Clients)",
y = "Energy Consumption",
color = "Day Type") +
theme_minimal() +
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5))
Daily Profiles (24h) - Occupancy for Weekdays
df_weekday$hour <- hour(df_weekday$time) + minute(df_weekday$time)/60.0
ggplot(df_weekday, aes(x = hour, y = occupancy, group = date(time))) +
geom_line(alpha = 0.2, color = "blue") +
stat_summary(aes(group = 1), fun = mean, geom = "line", color = "blue", size = 1.5, linetype = "solid") +
labs(title = "Daily Profiles of Occupancy (Weekdays)",
x = "Time of Day",
y = "Occupancy (WiFi Clients)") +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60), # interval 10 menit
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Daily Profiles (24h) - Occupancy for Weekends
df_weekend$hour <- hour(df_weekend$time) + minute(df_weekend$time)/60.0
ggplot(df_weekend, aes(x = hour, y = occupancy, group = date(time))) +
geom_line(alpha = 0.2, color = "blue") +
stat_summary(aes(group = 1), fun = mean, geom = "line", color = "blue", size = 1.5, linetype = "solid") +
labs(title = "Daily Profiles of Occupancy (Weekends)",
x = "Time of Day",
y = "Occupancy (WiFi Clients)") +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60),
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Daily Profiles (24h) - Occupancy (Weekdays and Weekends)
df$hour <- hour(df$time) + minute(df$time)/60.0
ggplot(df, aes(x = hour, y = occupancy, group = date(time))) +
geom_line(data = df_weekday, aes(color = "Weekdays"), alpha = 0.2) +
stat_summary(data = df_weekday, aes(color = "Weekdays", group = 1), fun = mean, geom = "line", size = 1.5, linetype = "solid") +
geom_line(data = df_weekend, aes(color = "Weekends"), alpha = 0.2, linetype = "dashed") +
stat_summary(data = df_weekend, aes(color = "Weekends", group = 1), fun = mean, geom = "line", size = 1.5, linetype = "dashed") +
labs(title = "Daily Profiles of Occupancy (Weekdays and Weekends)",
x = "Time of Day",
y = "Occupancy (WiFi Clients)") +
scale_color_manual(values = c("Weekdays" = "red", "Weekends" = "blue")) +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60),
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal() +
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5,size=30),
axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Daily Profiles (24h) - Energy Consumption for Weekdays
ggplot(df_weekday, aes(x = hour, y = energy_consumption, group = date(time))) +
geom_line(alpha = 0.2, color = "red") +
stat_summary(aes(group = 1), fun = mean, geom = "line", color = "red", size = 1.5, linetype = "solid") +
labs(title = "Daily Profiles of Energy Consumption (Weekdays)",
x = "Time of Day",
y = "Energy Consumption") +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60), # interval 10 menit
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),
axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Daily Profiles (24h) - Energy Consumption for Weekends
ggplot(df_weekend, aes(x = hour, y = energy_consumption, group = date(time))) +
geom_line(alpha = 0.2, color = "red") +
stat_summary(aes(group = 1), fun = mean, geom = "line", color = "red", size = 1.5, linetype = "solid") +
labs(title = "Daily Profiles of Energy Consumption (Weekends)",
x = "Time of Day",
y = "Energy Consumption") +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60), # interval 10 menit
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5,size=30),
axis.text.x = element_text(angle = 90, hjust = 1, size = 15))
Daily Profiles (24h) - Energy Consumption (Weekdays and Weekends)
ggplot(df, aes(x = hour, y = energy_consumption, group = date(time))) +
geom_line(data = df_weekday, aes(color = "Weekdays"), alpha = 0.2) +
stat_summary(data = df_weekday, aes(color = "Weekdays", group = 1), fun = mean, geom = "line", size = 1.5, linetype = "solid") +
geom_line(data = df_weekend, aes(color = "Weekends"), alpha = 0.2, linetype = "dashed") +
stat_summary(data = df_weekend, aes(color = "Weekends", group = 1), fun = mean, geom = "line", size = 1.5, linetype = "dashed") +
labs(title = "Daily Profiles of Energy Consumption (Weekdays and Weekends)",
x = "Time of Day",
y = "Energy Consumption") +
scale_color_manual(values = c("Weekdays" = "red", "Weekends" = "blue")) +
scale_x_continuous(
breaks = seq(0, 24, by = 10/60), # interval 10 menit
labels = function(x) sprintf("%02d:%02d", floor(x), round((x%%1)*60))
) +
theme_minimal()+
theme(legend.position = "bottom",plot.title = element_text(hjust = 0.5,size=30),
axis.text.x = element_text(angle = 90, hjust = 1, size = 15))