#preparing data and packages
library(readxl)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2     ✓ purrr   0.3.4
## ✓ tibble  3.0.4     ✓ dplyr   1.0.2
## ✓ tidyr   1.1.2     ✓ stringr 1.4.0
## ✓ readr   1.4.0     ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(ggplot2)
data<-read_xls("/home/idil/İndirilenler/ptf-smf.xls")

We are looking for MCP which is greater than 300 and SMP which is smaller than 300. Then we sort MCP descending order according to date. We then grouped the data with date.

#filtering data
data$Date = as.POSIXct(data$Date, format='%d.%m.%y %H:%M')
data %>%
  filter(MCP>300&SMP<300)%>%
  group_by(Date)%>%
  arrange("MCP",desc(Date))
## # A tibble: 47 x 6
## # Groups:   Date [47]
##    Date                MCP   SMP   `Positive Imbal… `Negative Imbal…
##    <dttm>              <chr> <chr> <chr>            <chr>           
##  1 2020-09-30 23:00:00 309.… 224.… 217.28           319.00          
##  2 2020-09-30 18:00:00 391.… 229.… 222.13           402.77          
##  3 2020-09-30 17:00:00 410.… 250.… 242.50           422.30          
##  4 2020-09-30 16:00:00 409.… 229.… 222.13           422.29          
##  5 2020-09-30 15:00:00 410.… 250.… 242.50           422.30          
##  6 2020-09-30 12:00:00 313.… 214.… 207.58           322.76          
##  7 2020-09-30 08:00:00 311.… 218.… 211.63           321.03          
##  8 2020-09-29 23:00:00 306.… 212.… 205.76           316.16          
##  9 2020-09-29 22:00:00 313.… 202.… 196.06           323.17          
## 10 2020-09-29 21:00:00 317.… 212.… 205.76           327.29          
## # … with 37 more rows, and 1 more variable: `SMP Direction` <chr>

We are plotting the data which we filtered and sorted before. In the plot both MCP and SMP increased at the end of the month.

#plotting the data
plot_df<-data %>%
  filter(MCP>300&SMP<300)%>%
  group_by(Date)%>%
  arrange("MCP",desc(Date))
  
ggplot(plot_df, aes(x=MCP, y=SMP, color=Date)) +
  geom_point()

#We are going to see when Energy Surplus happened
data %>%
  select(Date,`SMP Direction`)%>%
  filter(Date>"2020-09-15")%>%
  print()
## # A tibble: 383 x 2
##    Date                `SMP Direction` 
##    <dttm>              <chr>           
##  1 2020-09-15 01:00:00 ↑ Energy Deficit
##  2 2020-09-15 02:00:00 ↑ Energy Deficit
##  3 2020-09-15 03:00:00 ↑ Energy Deficit
##  4 2020-09-15 04:00:00 ↑ Energy Deficit
##  5 2020-09-15 05:00:00 ↑ Energy Deficit
##  6 2020-09-15 06:00:00 ↑ Energy Deficit
##  7 2020-09-15 07:00:00 ↓Energy Surplus 
##  8 2020-09-15 08:00:00 ↑ Energy Deficit
##  9 2020-09-15 09:00:00 ↑ Energy Deficit
## 10 2020-09-15 10:00:00 ↓Energy Surplus 
## # … with 373 more rows
#plotting the data
plot_df2<-data %>%
  filter(Date>"2020-09-15")

ggplot(plot_df2, aes(x=`SMP Direction`, y=Date)) +
  geom_tile()

As you can see in the second half of the month Energy Deficit is more than Energy Surplus and In Balance