In this study dplyr package is used for data manipulation, ggplt2 package is used for creating plots and visuals and lubridate package is used to make it easier to work with dates and times.
library(dplyr)
library(ggplot2)
library(lubridate)
library(readxl)
Elektrik <- read_excel("C:/Users/kamiu/Desktop/Elektrik.xlsx")
y <- Elektrik %>% mutate(Day1 = as_date(Tarih)) %>% mutate(Hour1 = hour(Tarih)) %>% mutate(WD = weekdays(Tarih))
y %>% glimpse()
## Rows: 720
## Columns: 9
## $ Tarih <dttm> 2020-09-01 00:00:00, 2020-09...
## $ `PTF/MCP` <dbl> 302.39, 300.25, 292.64, 290.0...
## $ `SMF/SMP` <dbl> 332.39, 325.25, 317.64, 320.0...
## $ `Pozitif Dengesizlik Fiyati (TL/MWh)` <dbl> 293.32, 291.24, 283.86, 281.3...
## $ `Negatif Dengesizlik Fiyati (TL/MWh)` <dbl> 342.36, 335.01, 327.17, 329.6...
## $ `SMF Yön` <chr> "Enerji Açigi", "Enerji Açigi...
## $ Day1 <date> 2020-09-01, 2020-09-01, 2020...
## $ Hour1 <int> 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,...
## $ WD <chr> "Tuesday", "Tuesday", "Tuesda...
v1 = y %>% rename('Imbalance Price - Positive(TL/MWh)' = `Pozitif Dengesizlik Fiyatı (TL/MWh)`, 'Imbalance Price - Negative(TL/MWh)' = `Negatif Dengesizlik Fiyatı (TL/MWh)`,Date_Time = Tarih, JDate=Day1,JTime=Hour1,JDay= WD, 'Energy Deficit_Surplus' = `SMF Yön`, 'Market Clearing Price'=`PTF/MCP`, 'System Marginal Price'=`SMF/SMP` )
v2 = v1 %>% mutate( "Energy Balance" = ifelse(`Market Clearing Price` > `System Marginal Price`, "Energy Surplus", ifelse(`Market Clearing Price` == `System Marginal Price`,"Balanced","Energy Deficit")))
v3 = v2%>%mutate("isWeekend"= ifelse(JDay== 'Monday','No',ifelse(JDay == 'Tuesday','No',ifelse(JDay == 'Wednesday','No',ifelse(JDay == 'Thursday','No',ifelse(JDay == 'Friday','No',ifelse(JDay == 'Saturday','Yes','Yes')))))))
plot1data = v2 %>% group_by(Days_of_the_Month = lubridate::day(Date_Time)) %>% summarise(Sum_of_SMP = sum(`System Marginal Price`))
ggplot(plot1data, aes(x=Days_of_the_Month, y=Sum_of_SMP)) +
geom_line()+ theme_minimal() +
labs(x = "Days of the Month",y = "Sum of System Margin Prices")
v2 %>% group_by(Days_of_the_Week = lubridate::wday(Date_Time, label=TRUE)) %>% summarise(Mean_of_SMP = mean(`System Marginal Price`))
## # A tibble: 7 x 2
## Days_of_the_Week Mean_of_SMP
## <ord> <dbl>
## 1 Sun 292.
## 2 Mon 322.
## 3 Tue 323.
## 4 Wed 333.
## 5 Thu 395.
## 6 Fri 333.
## 7 Sat 262.
ggplot(v2 %>% group_by(Days_of_the_Week = lubridate::wday(Date_Time, label=TRUE)) %>% summarise(Mean_of_SMP = mean(`System Marginal Price`)),aes(x="", y=Mean_of_SMP, fill=Days_of_the_Week)) +geom_bar(stat='identity',width = 1)+coord_polar("y")+
labs(x = "Days of the Week",y = "Average of System Margin Prices")
v4 = v3 %>% rename( SMP = 'System Marginal Price')
ggplot(v4, aes(x= JTime , y= SMP ,color=isWeekend)) +
geom_bar(stat='identity')+ theme_minimal() +
labs(x = "Hours of the Day",y = "Total System Marginal Price")