Codes for “Why Does the Unit Cost of YEKDEM Increase?” are presented below.

Contents

  1. Libraries

  2. Important Tables’ Names

  3. Data Manipulations

  4. Graphs

    1. Market Clearing Price (PTF) - Unit Cost

    2. Total Cost (YEKTOB) and Total Production Distributions in terms of Renewable Resources

    3. EPDK Forecasts for Unit Cost - Real Unit Cost

    4. Weighted Average of USD - TRY and Unit Cost

    5. Withdrawal Quantity Under Supply Liability (UEÇM) - Unit Cost

    6. The Amount of Hydro Power Plants’ Production - Unit Cost

Libraries

library(lubridate)
library(dplyr)
library(data.table)
library(ggplot2)
library(tidyverse)
library(zoo)
library(docxtractr)

Important Tables’ Names

load(url("https://github.com/alkimcelik/YEKDEM/raw/master/yekdem_tables.rdata"))

Data Manipulations

#Getting rid of months before July 2018
epdk_forecast_2018_first <- epdk_forecast_2018_first[c(7:12),] 

#Setting Column names of prediction tables 
colnames(epdk_forecast_2018_first) <- c("Date", "Forecast") 

colnames(epdk_forecast_2018_second) <- c("Date","Forecast")

colnames(epdk_forecast_2019_first) <- c("Date","Forecast")

colnames(epdk_forecast_2019_second) <- c("Date","Forecast")

# Due to incompatible date format of first predictions for 2018, setting the right format
epdk_forecast_2018_first$Date <- epdk_forecast_2018_second$Date

# Adding report dates to forecast reports
epdk_forecast_2018_first <- epdk_forecast_2018_first %>% mutate(report_date = "28/12/2017")

epdk_forecast_2018_second <- epdk_forecast_2018_second %>% mutate(report_date = "24/07/2018")

epdk_forecast_2019_first <- epdk_forecast_2019_first %>% mutate(report_date = "06/12/2018")

epdk_forecast_2019_second <- epdk_forecast_2019_second %>% mutate(report_date = "16/05/2019")

#Gathering all tables in one table
epdk_forecast <- rbind(epdk_forecast_2018_first,epdk_forecast_2018_second, epdk_forecast_2019_first, epdk_forecast_2019_second)

#Getting wide format
epdk_forecast <- dcast(epdk_forecast, Date~report_date, value.var = "Forecast")

#Changing format of date column of forecast to "datetime"
epdk_forecast$Date <- dmy(epdk_forecast$Date)

#In order to change the format to numeric, replacing dots with commas at columns except date 
epdk_forecast[,c(2:5)] <- lapply(epdk_forecast[,c(2:5)],function(x) as.numeric(as.character(gsub(",","\\.",x))))

#Changing format of date column of clearing quantity to "datetime"
clearing_quantity$Date <- dmy(clearing_quantity$Date)

#Due to quality between matched bids and offers, deleting the one of them
clearing_quantity$Matched.Offers <- NULL

#Changing matched bids column name in order to avoid some troubles that may occur because of dots
colnames(clearing_quantity)[colnames(clearing_quantity)=="Matched.Bids"] <- "Matched_Bids"

#Removing commas in matched bids
clearing_quantity$Matched_Bids <- gsub(",","",clearing_quantity$Matched_Bids)

#Changing matched bids format to numeric
clearing_quantity$Matched_Bids <- as.numeric(as.character(clearing_quantity$Matched_Bids))

#In rows below, needing months and years of each row in order to get monthly data
clearing_quantity <- clearing_quantity %>% mutate(Month = month(Date))

clearing_quantity <- clearing_quantity %>% mutate(Year = year(Date))

#Hours are needed for hourly activities, so it is merged with date
clearing_quantity$Date_Hour <- paste(clearing_quantity$Date, clearing_quantity$Hour)

#Removing date and hour columns, they are pasted each other, and exist in a new column
clearing_quantity[,c(1,2)] <- NULL

#Changing format to datetime
clearing_quantity$Date_Hour <- ymd_hm(clearing_quantity$Date_Hour)

#Changing format to character because it is needed for changing datetime format
license_production$Date <- as.character(license_production$Date)

#Changing format to datetime
license_production$Date <- dmy(license_production$Date)

#Months and years are needed for further rows to group the data
license_production$Month <- month(license_production$Date)

license_production$Year <- year(license_production$Date)

#Since total and other resources are not necessary, these are deleted
license_production[,c(3,13)] <- NULL

#Changing column names license_production columns
colnames(license_production) <- c("Date","Hour","Wind","Geothermal","Dammed_Hydro_Reservoir",
                                  "Canal_Type","Run_of_River","Land_Fill_Gas","Biogas","Sun",
                                  "Biomass","Month","Year")

# Changing format of resources columns from factor to character for operations
license_production[,c(3:6)] <-sapply(license_production[,c(3:6)], as.character)

# Removing commas of values at resources columns and changing format to numeric
for(i in 3:6){
     license_production[,i] <- as.numeric(gsub(",","",license_production[,i]))
   }

#Date columns is changed to date-hour format
license_production$Date <- paste(license_production$Date,license_production$Hour)

license_production$Hour <- NULL

license_production$Date <- ymd_hm(license_production$Date)

#Changing period hourly to monthly
license_production_monthly <- license_production %>% 
  group_by(Month,Year) %>% summarise(Wind = sum(Wind), Geothermal = sum(Geothermal),
                                     Dammed_Hydro_Reservoir=sum(Dammed_Hydro_Reservoir),
                                     Canal_Type = sum(Canal_Type), Run_of_River = sum(Run_of_River),
                                     Land_Fill_Gas = sum(Land_Fill_Gas), 
                                     Biogas=sum(Biogas),Sun = sum(Sun), Biomass = sum(Biomass))



#Operations done for license_production above are also applied to not_license_production

not_license_production$Date <- as.character(not_license_production$Date)

not_license_production$Date <- dmy(not_license_production$Date)

not_license_production$Month <- month(not_license_production$Date)

not_license_production$Year <- year(not_license_production$Date)

not_license_production[,c(3,9)] <- NULL

colnames(not_license_production) <- c("Date","Hour","Wind", "Biogas",
                                  "Canal_Type", "Biomass","Sun","Month","Year")

not_license_production$Sun <- as.character(not_license_production$Sun)

not_license_production$Sun <- as.numeric(gsub("\\,","",not_license_production$Sun))

not_license_production$Date <- paste(not_license_production$Date,not_license_production$Hour)

not_license_production$Hour <- NULL

not_license_production$Date <- ymd_hm(not_license_production$Date) 

not_license_production_monthly <- not_license_production %>% 
  group_by(Month,Year) %>% summarise(Wind = sum(Wind),
                                     Biogas=sum(Biogas),
                                     Canal_Type = sum(Canal_Type),
                                     Biomass = sum(Biomass),
                                     Sun = sum(Sun))

#Monthly licensed and licensed exempt generations are summed up
sources_monthly <- bind_rows(license_production_monthly[,c(1:3,9,6,11,10)],not_license_production_monthly) %>%
  group_by(Month,Year) %>% summarise_all(sum)

#Hourly licensed and licensed exempt generations are summed
sources_hourly <- bind_rows(license_production[,c(1,2,8,5,10,9)], not_license_production) %>% 
  group_by(Date) %>% summarise_all(sum)

#Unnecessary columns, which are month and year columns are removed
sources_hourly[,c(7,8)] <- NULL

#Licensed exempt generations do not include geothermal, dammed hydro with reservoir, run of river, land fill gas. These are added from licensed generation.
sources_hourly <- cbind(sources_hourly,license_production[,c(3,4,6,7,11,12)])

#Getting hourly total production from renewable resources
sources_hourly <- sources_hourly %>% mutate(Total_Production = Wind+Biogas+Dammed_Hydro_Reservoir+
                            Sun+Biomass+Canal_Type+Geothermal+Run_of_River+Land_Fill_Gas)


#Resources which belong to both licensed and licensed exempt generations are removed from licensed production monthly to merge easily
license_production_monthly[,c(1:3,6,9:11)] =NULL

#All reasources are gathered in one table 
sources_monthly <- cbind(sources_monthly,license_production_monthly)

#For date operations
sources_monthly$Day <- "01"

#Getting appropriate date format
sources_monthly$Date <-paste0(sources_monthly$Day,"/",sources_monthly$Month,"/",sources_monthly$Year)

#Getting rid of unnecesary columns
sources_monthly <- sources_monthly %>% ungroup() %>% 
  select(Date, Wind, Biogas, Canal_Type, Biomass, Sun, Geothermal, Dammed_Hydro_Reservoir, Run_of_River, Land_Fill_Gas)

#Changing format to datetime
sources_monthly$Date <- dmy(as.character(sources_monthly$Date))

#Ordering date
sources_monthly <- sources_monthly %>% arrange(Date)

#Changing column names for merging operations and clarity
colnames(unit_cost) <- c("Date","Unit_Cost")

#Changing format to numeric
unit_cost$Unit_Cost <- as.numeric(gsub(",",".",unit_cost$Unit_Cost))

#Avoiding long datetime operations, data of sources_monthly and unit_cost is arranged in the same order, so their datetime columns must be the same.
unit_cost$Date <- sources_monthly$Date

# Generation with tolerance and without tolerance are set apart.
sources_monthly_with_tolerance <- sources_monthly

# Generation amounts are multiplied with their tolerance coefficients.
sources_monthly_with_tolerance$Wind <- sources_monthly_with_tolerance$Wind*0.97

sources_monthly_with_tolerance$Biogas <- sources_monthly_with_tolerance$Biogas*0.99

sources_monthly_with_tolerance$Sun <- sources_monthly_with_tolerance$Sun*0.98

sources_monthly_with_tolerance$Biomass <- sources_monthly_with_tolerance$Biomass*0.99

sources_monthly_with_tolerance$Geothermal <- sources_monthly_with_tolerance$Geothermal*0.995

sources_monthly_with_tolerance$Land_Fill_Gas <- sources_monthly_with_tolerance$Land_Fill_Gas*0.99

sources_monthly_with_tolerance$Run_of_River <- sources_monthly_with_tolerance$Run_of_River*0.98

sources_monthly_with_tolerance$Canal_Type <- sources_monthly_with_tolerance$Canal_Type*0.98

#Water based production methods are gathered in one category, which is called "Hydro"
sources_monthly_with_tolerance <- sources_monthly_with_tolerance %>% mutate(Hydro = Dammed_Hydro_Reservoir+Run_of_River+Canal_Type)

#Waste based production methods are gathered in one category, which is called "Others"
sources_monthly_with_tolerance <- sources_monthly_with_tolerance %>% mutate(Others=Land_Fill_Gas+Biogas+Biomass)

#Total monthly production
sources_monthly_with_tolerance <- sources_monthly_with_tolerance %>% mutate(Total_Production = Wind+Others+Sun+Hydro+Geothermal)

#Selcting necessary columns
sources_monthly_with_tolerance <- sources_monthly_with_tolerance %>% select(Date, Wind, Sun, Geothermal, Hydro, Others, Total_Production)

#Transforming production from MWh to GWh
for(i in 2:7){
  sources_monthly_with_tolerance[,i] <- sources_monthly_with_tolerance[,i]/1000
}

#Unit cost and production with tolerance are gathered in one table
sources_monthly_with_tolerance_and_unit_cost <- merge(sources_monthly_with_tolerance,unit_cost, by="Date")

#To prepare share diagram, sources_monthly_without_incentive was created. Operations are below.
sources_monthly_without_incentive <- sources_monthly

#Water based production methods are gathered in one category, which is called "Hydro"
sources_monthly_without_incentive <- sources_monthly_without_incentive %>% 
  mutate(Hydro = Dammed_Hydro_Reservoir+ Run_of_River + Canal_Type)

#Waste based production methods are gathered in one category, which is called "Others"
sources_monthly_without_incentive <- sources_monthly_without_incentive %>% mutate(Others = Biomass + Biogas + Land_Fill_Gas)

#Selecting necessary columns
sources_monthly_without_incentive <- sources_monthly_without_incentive %>% 
  select(Date, Wind, Sun, Geothermal, Hydro, Others)

#Total of renewable resources
sources_monthly_without_incentive <- sources_monthly_without_incentive %>%  mutate(Total = rowSums(sources_monthly_without_incentive[,c(2:6)]))

#Getting ratios
for(i in 2:6){
  sources_monthly_without_incentive[,i] <- sources_monthly_without_incentive[,i]/sources_monthly_without_incentive$Total
}

sources_monthly_without_incentive$Total <- NULL

# Wind, Hydro values are multiplied with their incentive values (73$/MWh)
sources_monthly[,c(2,4,8,9)] <- sources_monthly[,c(2,4,8,9)] * 73 

#Geothermal values are multiplied with its incentive value (105$/MWh)
sources_monthly$Geothermal <- sources_monthly$Geothermal * 105

#Biomass, Biogas, Land Fill Gas, and Sun values are multiplied with their incentive values (133$/MWh)
sources_monthly[,c(3,5,6,10)] <- sources_monthly[,c(3,5,6,10)] * 133

#There occurs an empty column while exchange_rate is extracted.
exchange_rate$X <- NULL

#There are irrelevant rows, so they have to be removed.
exchange_rate <- exchange_rate[-c(368:375),]

#Changing column names for merging operations and clarity
colnames(exchange_rate) <- c("Date","Exchange_Rate")

#Changing format to datetime
exchange_rate$Date <- dmy(exchange_rate$Date)

#Changing format to numeric
exchange_rate$Exchange_Rate <- as.numeric(as.character(exchange_rate$Exchange_Rate))

#Since exchange market is closed at weekends, exchange rate on Saturdays and Sundays are filled with exchange rate on Friday before.
exchange_rate <- na.locf(exchange_rate)

#First two columns are out of the period we discuss, they are removed
exchange_rate <- exchange_rate[-c(1,2),]

#Giving appropriate name to Date - Hour column
colnames(sources_hourly)[colnames(sources_hourly)=="Date"] <- "Date_Hour"

#Taking dates from date_hour column
sources_hourly$Date <- date(sources_hourly$Date_Hour)

#Merging hourly generation from renewable resources with exchange rate in order to take weighted average of exchange rate
weighted_exchange_rate <- merge(sources_hourly,exchange_rate, by="Date")

#Taking necessary columns
weighted_exchange_rate <- weighted_exchange_rate %>% select(Date, Total_Production, Exchange_Rate)

#Mathematical operationS for weighted average
weighted_exchange_rate <- weighted_exchange_rate %>% mutate(Production_with_exchange_rate = Exchange_Rate*Total_Production)

weighted_exchange_rate <- weighted_exchange_rate %>% group_by(month(Date)) %>% mutate(Monthly_Total = sum(Production_with_exchange_rate))

weighted_exchange_rate <- weighted_exchange_rate %>% group_by(`month(Date)`) %>% mutate(Total_Production_Monthly = sum(Total_Production))

weighted_exchange_rate <- weighted_exchange_rate %>% mutate(Weighted_Exchange_Rate=Monthly_Total/Total_Production_Monthly)

#Date operations to get monthly data
weighted_exchange_rate <- weighted_exchange_rate %>% mutate(Year = year(Date))

weighted_exchange_rate$Day <- 01

#Selecting necessary columns
weighted_exchange_rate <- weighted_exchange_rate %>% select(Day, `month(Date)`, Year, Weighted_Exchange_Rate)

#Getting monthly data
weighted_exchange_rate <- weighted_exchange_rate %>% group_by(`month(Date)`,Year, Weighted_Exchange_Rate,Day) %>% summarise()

#Date operations for clarity
weighted_exchange_rate <- weighted_exchange_rate %>% mutate(Date = paste0(Day,"/",`month(Date)`,"/",Year))

weighted_exchange_rate$Date <- dmy(weighted_exchange_rate$Date)

#Selecting necessary columns
weighted_exchange_rate <- weighted_exchange_rate %>% ungroup() %>% select(Date, Weighted_Exchange_Rate)

#Ordering according to date
weighted_exchange_rate <- weighted_exchange_rate %>% arrange(Date)

#Finding YEKTOB
total_sources_with_expenses <- merge(sources_hourly,exchange_rate,by="Date")

#Multiplying the quantity of production with daily exchange rate
for(i in 3:11){
  total_sources_with_expenses[,i] <- total_sources_with_expenses[,i]*total_sources_with_expenses$Exchange_Rate
}

# Wind, Hydro values are multiplied with their incentive values (73$/MWh)
total_sources_with_expenses[,c(3,5,9,10)] <- total_sources_with_expenses[,c(3,5,9,10)] * 73 

#Geothermal values are multiplied with its incentive value (105$/MWh)
total_sources_with_expenses$Geothermal <- total_sources_with_expenses$Geothermal * 105

#Biomass, Biogas, Land Fill Gas, and Sun values are multiplied with their incentive values (133$/MWh)
total_sources_with_expenses[,c(4,6,7,11)] <- total_sources_with_expenses[,c(4,6,7,11)] * 133

#Hourly YEKTOB
total_cost_hourly <- total_sources_with_expenses %>% 
  select(Month,Year, Wind, Biogas, Canal_Type, Biomass, Biogas, Sun, Geothermal, Dammed_Hydro_Reservoir, Run_of_River, Land_Fill_Gas)

#Monthly YEKTOB
total_cost_monthly <- total_cost_hourly %>% group_by(Month,Year) %>% 
  summarise(Wind = sum(Wind), 
            Geothermal = sum(Geothermal),                                                                                               Dammed_Hydro_Reservoir=sum(Dammed_Hydro_Reservoir),
            Canal_Type = sum(Canal_Type), Run_of_River = sum(Run_of_River),
            Land_Fill_Gas = sum(Land_Fill_Gas), 
            Biogas=sum(Biogas),Sun = sum(Sun), Biomass = sum(Biomass))

#Date Operations
total_cost_monthly$Day <- 01

total_cost_monthly$Date <- paste0(total_cost_monthly$Day,"/",total_cost_monthly$Month,"/",total_cost_monthly$Year)

total_cost_monthly$Date <- dmy(total_cost_monthly$Date)

#Getting rid of unnecessary columns
total_cost_monthly <- total_cost_monthly %>% ungroup() %>%
  select(Date, Wind, Geothermal, Dammed_Hydro_Reservoir, Canal_Type, Run_of_River,Land_Fill_Gas, Biogas, Sun, Biomass)

#Ordering according to date
total_cost_monthly <- total_cost_monthly %>% arrange(Date)

#Setting appropriate column names
colnames(total_cost_monthly) <- c("Date", "Wind_Cost", "Geothermal_Cost","Dammed_Hydro_Reservoir_Cost",
                                  "Canal_Type_Cost","Run_of_River_Cost","Land_Fill_Gas_Cost",
                                  "Biogas_Cost","Sun_Cost","Biomass_Cost")

#For water based and waste based generation methods
total_cost_grouped <- total_cost_monthly

total_cost_grouped <- total_cost_grouped %>% mutate(Hydro_Cost=Dammed_Hydro_Reservoir_Cost + Canal_Type_Cost+ Run_of_River_Cost)

total_cost_grouped <- total_cost_grouped %>% mutate(Others_Cost = Biogas_Cost + Biomass_Cost + Land_Fill_Gas_Cost)

#Getting necessary columns
total_cost_grouped <- total_cost_grouped %>% select(Date, Wind_Cost, Sun_Cost, Geothermal_Cost, Hydro_Cost, Others_Cost)

#Operations for ratios of renewable resources 
total_cost_grouped <- total_cost_grouped %>% mutate(Total = rowSums(total_cost_grouped[,c(2:6)]))

for(i in 2:6){
  total_cost_grouped[,i] <- total_cost_grouped[,i]/total_cost_grouped$Total
}

total_cost_grouped$Total <- NULL

#For comparison of cost ratios of renewable resources and production ratios of them
total_consumption_with_unit_cost <- merge(sources_monthly_without_incentive,total_cost_monthly,by="Date")

#Taking necessary columns
market_clearing_price <- market_clearing_price %>% select(Date, Hour, MCP..TL.MWh.)

#changing format to character
market_clearing_price$Date <- as.character(market_clearing_price$Date)

#Changing format to datetime
market_clearing_price$Date <- dmy(market_clearing_price$Date)

#Renaming column names
colnames(market_clearing_price) <- c("Date","Hour","MCP")

#Date operations for market clearing price
market_clearing_price$Date <- paste(market_clearing_price$Date,market_clearing_price$Hour)

market_clearing_price$Hour <- NULL

market_clearing_price$Date <- ymd_hm(market_clearing_price$Date)

colnames(market_clearing_price)[colnames(market_clearing_price)=="Date"] <- "Date_Hour"

#In order to take weighted average of market clearing price, it is merged with hourly matched bids
sources_hourly_with_MCP <- merge(clearing_quantity,market_clearing_price,by="Date_Hour")

#Operations for taking weighted average of market clearing price
sources_hourly_with_MCP <- sources_hourly_with_MCP %>% mutate(MCP_multiply_clearing_quantity = Matched_Bids*MCP)

MCP_Monthly_and_Total_Revenue <- sources_hourly_with_MCP %>% group_by(Month,Year) %>% summarise(Total_Revenue = sum(MCP_multiply_clearing_quantity),Total_Production = sum(Matched_Bids))

MCP_Monthly_and_Total_Revenue$Weighted_Average_MCP <- MCP_Monthly_and_Total_Revenue$Total_Revenue/MCP_Monthly_and_Total_Revenue$Total_Production

#Date operations
MCP_Monthly_and_Total_Revenue$Day <- 01

MCP_Monthly_and_Total_Revenue$Date <-paste0(MCP_Monthly_and_Total_Revenue$Day,"/",MCP_Monthly_and_Total_Revenue$Month,"/",MCP_Monthly_and_Total_Revenue$Year)

#Selecting necessary columns
MCP_Monthly_and_Total_Revenue <- MCP_Monthly_and_Total_Revenue %>% ungroup() %>%
  select(Date, Total_Revenue, Total_Production, Weighted_Average_MCP)

#Date operations
MCP_Monthly_and_Total_Revenue$Date <- dmy(MCP_Monthly_and_Total_Revenue$Date)

MCP_Monthly_and_Total_Revenue <- MCP_Monthly_and_Total_Revenue %>% arrange(Date)

#For comparison
weighted_MCP_with_Unit_Cost <- cbind(unit_cost, MCP_Monthly_and_Total_Revenue[,4])

colnames(total_consumption)[colnames(total_consumption)=="Withdrawal.Quantity.Under.Supply.Liability..MWh."] <- "Consumption"

#Avoiding long datetime operations, data of sources_monthly and unit_cost is arranged in the same order, so their datetime columns must be the same.
total_consumption$Date <- weighted_MCP_with_Unit_Cost$Date

#Removing commas
total_consumption$Consumption <- gsub(",","",total_consumption$Consumption)

#Changing format to numeric
total_consumption$Consumption <- as.numeric(as.character(total_consumption$Consumption))

#For Total consumption - unit cost graph
total_consumption_with_unit_cost <- merge(total_consumption,unit_cost,by="Date")

#Changing unit MWh to GWh
total_consumption_with_unit_cost$Consumption <- total_consumption_with_unit_cost$Consumption/1000

#For the graph of cost and production shares
total_cost_and_production <- merge(sources_monthly_without_incentive,total_cost_grouped, by="Date")

#Making long format
total_cost_and_production <- melt(total_cost_and_production, id.vars = "Date")

total_cost_and_production <- setDT(total_cost_and_production)

#Deciding either cost or production
total_cost_and_production[,Type:=case_when(variable%like%"Cost"~"Cost")]

total_cost_and_production[is.na(total_cost_and_production),] <- "Production"

#Changing order of columns
total_cost_and_production <- total_cost_and_production[,c(1,4,2,3)]

#Changing format to character
total_cost_and_production$variable <- as.character(total_cost_and_production$variable)

#Adding marker for graph
total_cost_and_production <- total_cost_and_production %>% mutate(Marker = case_when(variable %like% "Wind"~"Wind",
                                                        variable %like% "Hydro"~"Hydro",
                                                        variable %like% "Sun"~"Sun",
                                                        variable %like% "Geothermal"~"Geothermal",
                                                        variable %like% "Others"~"Others"))



#For comparison of EPDK Forecast and unit cost
epdk_forecast_with_unit_cost <- merge(epdk_forecast, unit_cost, by="Date")

#For comparison of exchange rate and unit cost
exchange_rate_with_unit_cost <- merge(unit_cost,weighted_exchange_rate,by="Date")

#Setting long format
weighted_MCP_with_Unit_Cost <- melt(weighted_MCP_with_Unit_Cost, id.vars = "Date")

colnames(weighted_MCP_with_Unit_Cost)[colnames(weighted_MCP_with_Unit_Cost)=="variable"] <- "Type"

#Ordering columns
epdk_forecast_with_unit_cost <- epdk_forecast_with_unit_cost[,c(1,5,4,2,3,6)]

colnames(epdk_forecast_with_unit_cost) <- c("Date","first","second","third","fourth","Unit_Cost")

Graphs

1) Market Clearing Price (PTF) - Unit Cost

ggplot(weighted_MCP_with_Unit_Cost, aes(x=Date, y=value)) + geom_bar(aes(fill=Type),stat = "identity", position = "stack") +  scale_fill_manual(labels = c("Unit Cost", "Weighted Average of MCP"), values = c("red","blue")) + theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5, size=16),legend.text = element_text(size = 13), legend.title = element_blank(), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12)) + labs(y="Value (TL)", title = "Comparison of the Unit Cost and Weighted Average of MCP") 

2) Total Cost (YEKTOB) and Total Production Distributions in terms of Renewable Resources

barwidth = 10
ggplot() + geom_bar(data = filter(total_cost_and_production, Type=="Cost"), aes(x=Date-barwidth/2 - 1 , y = value, fill = Marker), stat = "identity", position = "stack", width = barwidth) +
  geom_bar(data = filter(total_cost_and_production, Type == "Production"), aes(x=Date + barwidth/2 + 1 , y = value, fill=Marker),
           stat = "identity", position = "stack", width = barwidth) + scale_fill_brewer(palette = "Set1") +
  geom_text(data = filter(total_cost_and_production, Type=="Cost"),
            aes(x=Date-barwidth/2-1, y = 0.7,label = paste(Type,"(TL)"), angle = 90), size = 5, colour="white")+ 
  geom_text(data = filter(total_cost_and_production, Type == "Production"), 
            aes(x=Date+barwidth/2+1, y = 0.7,label = paste(Type,"(MWh)"), angle = 90), size = 5, colour = "white") +
 labs(x="Date", y="Shares", title = "Shares of Renewables in terms of Cost and Production", fill="Renewable Resources")+
  theme_minimal() + theme(axis.ticks.y = element_blank(), axis.text.y = element_blank(), legend.text = element_text(size = 13), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12), plot.title = element_text(size = 16, hjust = 0.5), legend.title = element_text(size = 14))

3) EPDK Forecasts for Unit Cost - Real Unit Cost

ggplot(data = epdk_forecast_with_unit_cost, aes(x=Date)) + geom_line(aes(y=first, color="aquamarine4"))+
  geom_line(aes(y=second, color="blue"))+ geom_line(aes(y=third, color="darkgoldenrod4"))+ 
  geom_line(aes(y=Unit_Cost,color="red")) + geom_point(aes(y=first, color="aquamarine4"), size = 3) +
  geom_point(aes(y=second, color="blue"),  size = 3) + geom_point(aes(y=third, color="darkgoldenrod4"), size = 3) +
  geom_point(aes(y=fourth, color="darkgreen"),  size = 3) +
  geom_point(aes(y=Unit_Cost, color = "red"),  size = 3) + theme_minimal() + 
  scale_color_manual(name = "", labels = c("Forecast on 28/12/2017","Forecast on 24/07/2018","Forecast on 06/12/2018",
                                           "Forecast on 16/05/2019","Unit Cost"), 
                     values = c("aquamarine4","blue","darkgoldenrod4","darkgreen","red")) +
  labs(title = "Comparison of EPDK Forecast and Unit Cost", y="Values (TL/MWh)") + 
  theme(legend.text = element_text(size = 13), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12), axis.text.y = element_text(size = 12), plot.title = element_text(size = 16, hjust = 0.5))

4) Weighted Average of USD - TRY and Unit Cost

ggplot(data = exchange_rate_with_unit_cost, aes(x=Date)) + geom_line(aes(y=Unit_Cost, color = "red"))+
  geom_point(aes(y=Unit_Cost, color = "red")) +
  geom_line(aes(y=Weighted_Exchange_Rate*20, color = "darkslateblue")) +
  geom_point(aes(y = Weighted_Exchange_Rate*20, color = "darkslateblue")) +
  scale_y_continuous(sec.axis = sec_axis(~./20, name = "Weighted Average of USD - TRY ($/TL)")) + 
  scale_colour_manual(name = "", labels = c("USD - TRY Exchange Rate", "Unit Cost"), values = c("darkslateblue","red")) +
  labs(y = "Unit Cost (TL)",title = "USD - TRY  and Unit Cost") + theme_minimal() +
  theme(legend.text = element_text(size = 13), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12), axis.text.y = element_text(size = 12), plot.title = element_text(size = 16, hjust = 0.5))

5) Withdrawal Quantity Under Supply Liability (UEÇM) - Unit Cost

ggplot(total_consumption_with_unit_cost, aes(x=Date)) + geom_line(aes(y=Unit_Cost,color = "darkgreen"))+
  geom_point(aes(y=Unit_Cost,color = "darkgreen")) +
  geom_line(aes(y=Consumption/150, color = "red")) +
  geom_point(aes(y=Consumption/150, color = "red")) + 
  scale_y_continuous(sec.axis = sec_axis(~.*150, name = "Withdrawal Quantity Under Supply Liability(GWh)"))+
  scale_color_manual(name="", labels = c("Unit Cost", "Withdrawal Quantity Under\nSupply Liability"), 
                     values = c("red","darkgreen")) + 
  labs(y="Unit Cost (TL)", title = "Comparison of Withdrawal Quantity Under Supply Liability and Unit Cost")+
  theme_minimal() +
  theme(legend.text = element_text(size = 13), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12), axis.text.y = element_text(size = 12), plot.title = element_text(size = 16, hjust = 0.5)) 

6) The Amount of Hydro Power Plants’ Production - Unit Cost

ggplot(sources_monthly_with_tolerance_and_unit_cost, aes(x=Date)) + geom_line(aes(y=Unit_Cost, color = "darkcyan")) + 
  geom_point(aes(y=Unit_Cost, color = "darkcyan")) + geom_line(aes(y=Hydro/40, color = "red"))+
  geom_point(aes(y=Hydro/40, color = "red")) + 
  scale_y_continuous(sec.axis = sec_axis(~.*40, name = "Production with Tolerance(GWh)")) +
  scale_color_manual(name="", labels = c("Unit Cost","Hydro Power Plants' Production"), values = c("red","darkcyan")) +
  labs(y="Unit Cost (TL)", title = "Comparison of Production From Hydro Power Plants and Unit Cost") + theme_minimal()+
  theme(legend.text = element_text(size = 13), axis.title.y = element_text(size = 15), axis.title.x = element_text(size = 15), axis.text.x = element_text(size = 12), axis.text.y = element_text(size = 12), plot.title = element_text(size = 16, hjust = 0.5))