#script for the following plots:
# - rmse value over lead time (literature) -> l.40-66
# - rmse value over lead time (synth) -> l.69-94
# - forecasting error histogram (offwind) -> l.104-248
# - forecasting error histogram (onwind) ->l.252-396
# - forecasting error histogram (solar) -> l.400-544
# - dotplot (offwind) -> l.551-568
# - dotplot (onwind) -> l.571-588
# - dotplot (solar) -> l.590-607
# - ribbon plot (offwind/onwind/pc) -> l.610-685



#-------------------------------------------------------------
#rmse values (literature)

prob_lit <- data.frame(x = prob_onwind$X,
                y = c(prob_onwind$RMSE...., prob_offwind$RMSE...., prob_solar$RMSE....),
                group = c(rep('onshore wind', nrow(prob_onwind)),
                        rep('offshore wind', nrow(prob_offwind)),
                        rep('photovoltaic', nrow(prob_solar))))                        



#-------------------------------------------------------------------------------
#importing libraries
library(ggplot2)
library(tidyr)
library(dplyr)
library("ggthemes")
library("ggpubr")



#importing dataframes
prob_onwind <- read.csv("Rdata/probability/prob_onwind.csv")
prob_offwind <- read.csv("Rdata/probability//prob_offwind.csv") 
prob_solar <- read.csv("Rdata/probability//prob_solar.csv") 

synthCorrectSd <- read.csv("Rdata/probability//synthCorrectSd.csv") 


probM_onwind <- read.csv("Rdata/probability//probabilityMatrix_onwind.csv")
probM_offwind <- read.csv("Rdata/probability//probabilityMatrix_offwind.csv")
probM_solar <- read.csv("Rdata/probability//probabilityMatrix_solar.csv")




ggp_lit <- ggplot(prob_lit, aes(x=x/4, y=y)) +
  geom_line(aes(color=group), size=1.3) + 
  scale_color_manual(values=c("#33beff", "#3358ff",  "#ffe333"))+
  scale_y_continuous(breaks=seq(0,15,by=2)) +
  scale_x_continuous(breaks=seq(0,36,by=2)) +
  labs(x="forecasting lead-time [h]",
       y="RMSE [% of P installed]",
       color="")+
  theme_set(theme_bw(base_size = 20))+
  theme(legend.position="bottom")


ggp_lit

ggsave("rmse_lit.pdf", width = 34, height = 20, units = "cm")






#rmse values (synth) - (values for entire year)

prob_synth <- data.frame(x = synthCorrectSd$X,
                       y = c(synthCorrectSd$onwind*100, synthCorrectSd$offwind*100,synthCorrectSd$solar*100),
                       group = c(rep('onshore wind', nrow(synthCorrectSd)),
                                 rep('offshore wind', nrow(synthCorrectSd)),
                                 rep('photovoltaic', nrow(synthCorrectSd))))                        



ggp_synth <- ggplot(prob_synth, aes(x=x/4, y=y)) +
  geom_line(aes(color=group), size=1.3) + 
  scale_color_manual(values=c("#33beff", "#3358ff",  "#ffe333"))+
  scale_y_continuous(breaks=seq(0,28,by=2)) +
  scale_x_continuous(breaks=seq(0,36,by=2)) +
  labs(x="forecasting lead-time [h]",
       y="standard deviation [% of power output]",
       color="")+
  theme_set(theme_bw(base_size = 20))+
  theme(legend.position="bottom")

ggp_synth

ggsave("rmse_synth.pdf", width = 34, height = 20, units = "cm")





#-----------------------------------------------------------------------------------------------------------------------------------
#ribbon plot offwind:

f= gather(probM_offwind[1:5000], key='year', value='deviation', 2:5000)

ribbonPlotOffwind<-ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.01), fun.max = function(x) quantile(x, 0.99), fill="gray75")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.05), fun.max = function(x) quantile(x, 0.95), fill="gray50")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.25), fun.max = function(x) quantile(x, 0.75), fill="gray25")+
  scale_y_continuous(breaks=seq(-70,70,by=10)) +
  scale_x_continuous(breaks=seq(0,37,by=2)) +
  annotate("text", x=30, y=0, label="Quantile: [0.25,0.75]", color="white", size=6)+
  annotate("text", x=30, y=30, label="Quantile: [0.05,0.95]", color="white", size=6)+
  annotate("text", x=30, y=53, label="Quantile: [0.01,0.99]", color="black", size=6)+
  labs(x="lead time [h]",
       y="forecasting error [%]",
       color="") +
  theme_set(theme_bw(base_size = 20))+
  theme(legend.position="bottom")

ribbonPlotOffwind
ggsave("ribbonPlotOffwind.pdf", width = 34, height = 20, units = "cm")



#ribbon plot onwind:

f= gather(probM_onwind[1:5000], key='year', value='deviation', 2:5000)


ribbonPlotOnwind<-ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.01), fun.max = function(x) quantile(x, 0.99), fill="gray75")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.05), fun.max = function(x) quantile(x, 0.95), fill="gray50")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.25), fun.max = function(x) quantile(x, 0.75), fill="gray25")+
  scale_y_continuous(breaks=seq(-60,60,by=10)) +
  scale_x_continuous(breaks=seq(0,37,by=2)) +
  annotate("text", x=30, y=0, label="Quantile: [0.25,0.75]", color="white", size=6)+
  annotate("text", x=30, y=25, label="Quantile: [0.05,0.95]", color="white", size=6)+
  annotate("text", x=30, y=45, label="Quantile: [0.01,0.99]", color="black", size=6)+
  labs(x="lead time [h]",
       y="forecasting error [%]",
       color="") +
  theme_set(theme_bw(base_size = 20))+
  theme(legend.position="bottom")

ribbonPlotOnwind
ggsave("ribbonPlotOnwind.pdf", width = 34, height = 20, units = "cm")



#ribbon plot solar:

f= gather(probM_solar[1:5000], key='year', value='deviation', 2:5000)


ribbonPlotSolar<-ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.01), fun.max = function(x) quantile(x, 0.99), fill="gray75")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.05), fun.max = function(x) quantile(x, 0.95), fill="gray50")+
  stat_summary(geom="ribbon", fun.min = function(x) quantile(x, 0.25), fun.max = function(x) quantile(x, 0.75), fill="gray25")+
  scale_y_continuous(breaks=seq(-70,70,by=10)) +
  scale_x_continuous(breaks=seq(0,37,by=2)) +
  annotate("text", x=30, y=0, label="Quantile: [0.25,0.75]", color="white", size=6)+
  annotate("text", x=30, y=27, label="Quantile: [0.05,0.95]", color="white", size=6)+
  annotate("text", x=30, y=48, label="Quantile: [0.01,0.99]", color="black", size=6)+
  labs(x="lead time [h]",
       y="forecasting error [%]",
       color="") +
  theme_set(theme_bw(base_size = 20))+
  theme(legend.position="bottom")

ribbonPlotSolar
ggsave("ribbonPlotsolar.pdf", width = 34, height = 20, units = "cm")














#------------------------------------------------------------------------------------------
#realised probability distribution:


#----------------------------------------
#histogram offshore wind:

#leadtime 1
l1 = gather(probM_offwind[5, 1:5000], key='year', value='deviation', 2:5000)
l1_ggp <- ggplot(l1, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 2
l2 = gather(probM_offwind[9, 1:5000], key='year', value='deviation', 2:5000)
l2_ggp <- ggplot(l2, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 3
l3 = gather(probM_offwind[13, 1:5000], key='year', value='deviation', 2:5000)
l3_ggp <- ggplot(l3, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 4
l4 = gather(probM_offwind[17, 1:5000], key='year', value='deviation', 2:5000)
l4_ggp <- ggplot(l4, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 8
l8 = gather(probM_offwind[33, 1:5000], key='year', value='deviation', 2:5000)
l8_ggp <- ggplot(l8, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 12
l12 = gather(probM_offwind[49, 1:5000], key='year', value='deviation', 2:5000)
l12_ggp <- ggplot(l12, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 18
l18 = gather(probM_offwind[73, 1:5000], key='year', value='deviation', 2:5000)
l18_ggp <- ggplot(l18, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 24
l24 = gather(probM_offwind[97, 1:5000], key='year', value='deviation', 2:5000)
l24_ggp <- ggplot(l24, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 36
l36 = gather(probM_offwind[145, 1:5000], key='year', value='deviation', 2:5000)
l36_ggp <- ggplot(l36, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,10)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#arrange plots on one page:
histograms <- ggarrange(l1_ggp, l2_ggp, l3_ggp, l4_ggp, l8_ggp, l12_ggp, l18_ggp, l24_ggp, l36_ggp,
          labels = c("1h", "2h", "3h", "4h", "8h", "12h", "18h", "24h", "36h"),
          label.x = 0.2,
          ncol = 3, nrow = 3)



annotate_figure(histograms,
                top = text_grob("Distribution of offshore wind forecasting errors (selected lead times)", face = "bold", size = 18),
                left = text_grob("density [%]", rot = 90),
                bottom = text_grob("deviation [p.u.]"))


#----------------------------------------
#histogram onshore wind:

#leadtime 1
l1 = gather(probM_onwind[5, 1:5000], key='year', value='deviation', 2:5000)
l1_ggp <- ggplot(l1, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 2
l2 = gather(probM_onwind[9, 1:5000], key='year', value='deviation', 2:5000)
l2_ggp <- ggplot(l2, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))


#leadtime 3
l3 = gather(probM_onwind[13, 1:5000], key='year', value='deviation', 2:5000)
l3_ggp <- ggplot(l3, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))

#leadtime 4
l4 = gather(probM_onwind[17, 1:5000], key='year', value='deviation', 2:5000)
l4_ggp <- ggplot(l4, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 8
l8 = gather(probM_onwind[33, 1:5000], key='year', value='deviation', 2:5000)
l8_ggp <- ggplot(l8, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 12
l12 = gather(probM_onwind[49, 1:5000], key='year', value='deviation', 2:5000)
l12_ggp <- ggplot(l12, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 18
l18 = gather(probM_onwind[73, 1:5000], key='year', value='deviation', 2:5000)
l18_ggp <- ggplot(l18, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 24
l24 = gather(probM_onwind[97, 1:5000], key='year', value='deviation', 2:5000)
l24_ggp <- ggplot(l24, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 36
l36 = gather(probM_onwind[145, 1:5000], key='year', value='deviation', 2:5000)
l36_ggp <- ggplot(l36, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,8)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#arrange plots on one page:
histograms <- ggarrange(l1_ggp, l2_ggp, l3_ggp, l4_ggp, l8_ggp, l12_ggp, l18_ggp, l24_ggp, l36_ggp,
                        labels = c("1h", "2h", "3h", "4h", "8h", "12h", "18h", "24h", "36h"),
                        label.x = 0.2,
                        ncol = 3, nrow = 3)



annotate_figure(histograms,
                top = text_grob("Distribution of onshore wind forecasting errors (selected lead times)", face = "bold", size = 18),
                left = text_grob("density [%]", rot = 90),
                bottom = text_grob("deviation [p.u.]"))


#----------------------------------------
#histogram solar:

#leadtime 1
l1 = gather(probM_solar[5, 1:5000], key='year', value='deviation', 2:5000)
l1_ggp <- ggplot(l1, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 2
l2 = gather(probM_solar[9, 1:5000], key='year', value='deviation', 2:5000)
l2_ggp <- ggplot(l2, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 3
l3 = gather(probM_solar[13, 1:5000], key='year', value='deviation', 2:5000)
l3_ggp <- ggplot(l3, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))

#leadtime 4
l4 = gather(probM_solar[17, 1:5000], key='year', value='deviation', 2:5000)
l4_ggp <- ggplot(l4, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white"))+
  theme(panel.background = element_rect(fill = "white"))


#leadtime 8
l8 = gather(probM_solar[33, 1:5000], key='year', value='deviation', 2:5000)
l8_ggp <- ggplot(l8, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))

#leadtime 12
l12 = gather(probM_solar[49, 1:5000], key='year', value='deviation', 2:5000)
l12_ggp <- ggplot(l12, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))


#leadtime 18
l18 = gather(probM_solar[73, 1:5000], key='year', value='deviation', 2:5000)
l18_ggp <- ggplot(l18, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))

#leadtime 24
l24 = gather(probM_solar[97, 1:5000], key='year', value='deviation', 2:5000)
l24_ggp <- ggplot(l24, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))

#leadtime 36
l36 = gather(probM_solar[145, 1:5000], key='year', value='deviation', 2:5000)
l36_ggp <- ggplot(l36, aes(x=deviation)) +
  xlim(0.5,1.5) +
  geom_histogram(aes(y=..density..), fill= "#aaa9a8", bins=90)+
  geom_density(alpha=.01, fill="#FF6666")+
  labs(x="",
       y="",
       color="")+
  ylim(0,6)+
  theme_fivethirtyeight() +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white"))


#arrange plots on one page:
histograms <- ggarrange(l1_ggp, l2_ggp, l3_ggp, l4_ggp, l8_ggp, l12_ggp, l18_ggp, l24_ggp, l36_ggp,
                        labels = c("1h", "2h", "3h", "4h", "8h", "12h", "18h", "24h", "36h"),
                        label.x = 0.2,
                        ncol = 3, nrow = 3)



annotate_figure(histograms,
                top = text_grob("Distribution of solar pv forecasting errors (selected lead times)", face = "bold", size = 18),
                left = text_grob("density [%]", rot = 90),
                bottom = text_grob("deviation [p.u.]"))




#--------------------------------------------------------------------------

#dotplot (somewhat heatmap) - offwind
f= gather(probM_offwind[1:1000], key='year', value='deviation', 2:1000)

ggp_offwind <- ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  geom_point(alpha=0.02) + 
  labs(title = "Realized forecasting errors offshore wind over lead time",
       subtitle = "Based on synthetic RMSE",
       x="lead time [h]",
       y="deviation [%]",
       color="") +
  theme_fivethirtyeight() +
  theme(axis.title = element_text()) +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white")) +
  theme(legend.background = element_rect(fill = "white")) +
  theme(legend.key = element_rect(fill = "white"))

ggp_offwind


#dotplot (somewhat heatmap) - onwind
f= gather(probM_onwind[1:1000], key='year', value='deviation', 2:1000)

ggp_onwind <- ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  geom_point(alpha=0.02) + 
  labs(title = "Realized forecasting errors onshore wind over lead time",
       subtitle = "Based on synthetic RMSE",
       x="lead time [h]",
       y="deviation [%]",
       color="") +
  theme_fivethirtyeight() +
  theme(axis.title = element_text()) +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white")) +
  theme(legend.background = element_rect(fill = "white")) +
  theme(legend.key = element_rect(fill = "white"))

ggp_onwind

#dotplot (somewhat heatmap) - solar
f= gather(probM_solar[1:1000], key='year', value='deviation', 2:1000)

ggp_solar <- ggplot(f, aes(x=X/4, y=(deviation*100-100))) +
  geom_point(alpha=0.02) + 
  labs(title = "Realized forecasting errors solar pv over lead time",
       subtitle = "Based on synthetic RMSE",
       x="lead time [h]",
       y="deviation [%]",
       color="") +
  theme_fivethirtyeight() +
  theme(axis.title = element_text()) +
  theme(plot.background = element_rect(fill = "white")) +
  theme(panel.background = element_rect(fill = "white")) +
  theme(legend.background = element_rect(fill = "white")) +
  theme(legend.key = element_rect(fill = "white"))

ggp_solar


