Commit e3433c92 authored by Matteo DE FELICE's avatar Matteo DE FELICE

New plots and bug fixing

parent 4160361e
......@@ -6,7 +6,6 @@ shinyServer(function(input, output, session) {
choices = zones[-1])
})
output$main_plot <- renderPlot({
# TODO Date is variable -> especially length out
res = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Reservoirs') %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
hrgen = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Hydro power generation') %>%
......@@ -15,6 +14,8 @@ shinyServer(function(input, output, session) {
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
wv = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Water value') %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
pf = readxl::read_xlsx(paste0('xls/', input$result_xls), sheet = 'Power flow') %>%
mutate(date = seq(as_datetime('2016-01-01'), by = 'day', length.out = n()))
# Load ENTSOE Data
entsoe_storage = read_rds('data/ENTSOE-Storage-2015-2018.rds')
# Average water value ---------------------------------------------------------------------
......@@ -63,13 +64,19 @@ shinyServer(function(input, output, session) {
color_palette = c('HPHS' = 'blue4',
'HDAM' = 'blue3',
'HROR' = 'blue2',
'HROR' = 'cornflowerblue',
'SUN' = 'yellow',
'PHOT' = 'yellow',
'GTUR' = 'brown3',
'STUR' = 'brown4',
'GAS' = 'brown2',
'WIN' = 'chartreuse2',
'COMC' = 'brown2',
'WIN' = 'chartreuse2',
'WTOF' = 'chartreuse2',
'WTON' = 'chartreuse2',
'BIO' = 'darkolivegreen1',
'OIL' = 'brown',
'ICEN' = 'grey66',
'HRD' = 'black')
g = sel_zone %>%
......@@ -84,7 +91,51 @@ shinyServer(function(input, output, session) {
ggplot(aes(x = date, y = generation, group = source_type,
fill = source_type)) +
scale_fill_manual(values = color_palette) +
geom_area()
geom_area() +
theme_light()
print(g)
}
# Generation stacked ----------------------------------------------------------------------------
else if (input$plot_type == 'gen_stacked') {
color_palette = c('HPHS' = 'blue4',
'HDAM' = 'blue3',
'HROR' = 'cornflowerblue',
'SUN' = 'yellow',
'PHOT' = 'yellow',
'GTUR' = 'brown3',
'STUR' = 'brown4',
'GAS' = 'brown2',
'COMC' = 'brown2',
'WIN' = 'chartreuse2',
'WTOF' = 'chartreuse2',
'WTON' = 'chartreuse2',
'BIO' = 'darkolivegreen1',
'OIL' = 'brown',
'ICEN' = 'grey66',
'HRD' = 'black')
gen_area = gen %>%
select(-X__1) %>%
gather(zone, generation, -date) %>%
mutate(country = str_split(zone, '_', simplify = TRUE)[,1],
type = str_split(zone, '_', simplify = TRUE)[,2],
year = lubridate::year(date)) %>%
group_by(date, country, type) %>%
summarise(generation = sum(generation)) %>%
group_by(date, country) %>%
mutate(daily_total = sum(generation)) %>%
ungroup() %>%
mutate(generation_fraction = generation / daily_total)
g = ggplot(gen_area, aes(x = date, y = generation_fraction, fill = type,
group = type)) +
geom_area(size = 0.5, colour = 'black', alpha = 0.8) +
facet_wrap(~country) +
scale_fill_manual(values = color_palette) +
theme_light()
print(g)
}
......@@ -103,7 +154,7 @@ shinyServer(function(input, output, session) {
color_palette = c('HPHS' = 'blue4',
'HDAM' = 'blue3',
'HROR' = 'blue2',
'HROR' = 'cornflowerblue',
'SUN' = 'yellow',
'PHOT' = 'yellow',
'GTUR' = 'brown3',
......@@ -128,18 +179,24 @@ shinyServer(function(input, output, session) {
# Reservoir levels single ------------------------------------------------------------------
else if (input$plot_type == 'res_single') {
res_zone = select(res, date, value = contains(paste0(input$zone, '_HPHS')),
value = contains(paste0(input$zone, '_HDAM'))) %>%
mutate(day_of_the_year = yday(date))
res_zone = select(res, date, contains(paste0(input$zone, '_HPHS')),
contains(paste0(input$zone, '_HDAM'))) %>%
mutate(day_of_the_year = yday(date)) %>%
gather(area, level, -date, -day_of_the_year)
entsoe_data = entsoe_storage %>%
filter(country == input$zone)
g = ggplot(res_zone, aes(x = day_of_the_year, y = value)) +
g = ggplot(res_zone, aes_string(x = ifelse(diff(range(res_zone$date)) > years(1),
"date",
"day_of_the_year"), y = "level", color = "area")) +
geom_line(size = 2) +
# ylab('GWh/day') +
theme(axis.text.x = element_text(size = 4, angle = 45, hjust = 1))
theme_light() +
theme(axis.text.x = element_text(size = 8, angle = 45, hjust = 1),
legend.position = 'bottom')
if (nrow(entsoe_data) > 0) {
g = g +
geom_line(data = entsoe_data, aes(x = day_of_the_year, y = value, color = as.factor(year)))
}
......@@ -158,6 +215,27 @@ shinyServer(function(input, output, session) {
theme(axis.text.x = element_text(size = 6, angle = 45, hjust = 1),
legend.position = 'bottom')
print(g)
# Power flows ---------------------------------------------------------------------------------
} else if (input$plot_type == 'pf') {
this_pf = pf %>%
select(-X__1) %>%
gather(line, flow, -date) %>%
group_by(line) %>%
mutate(smooth_flow = zoo::rollmean(flow, 7, fill = NA))
date_label = this_pf %>% group_by(date) %>% summarise(v = var(flow)) %>% arrange(-v) %>% pull(date)
g = ggplot(this_pf, aes(x = date, y = smooth_flow, color = line)) + geom_line() +
ggrepel::geom_label_repel(data = filter(this_pf, date == date_label[1]),
aes(label = line),
force = 5,
segment.color = "grey50",
nudge_x =5) +
theme_light() +
theme(axis.text.x = element_text(size = 6, angle = 45, hjust = 1),
legend.position = 'none')
print(g)
}
})
......
......@@ -18,7 +18,9 @@ shinyUI( fluidPage(
'reservoir levels (all)' = 'res_all',
'reservoir levels (single)' = 'res_single',
'generation mix' = 'gen_mix',
'generation yearly' = 'gen_year')),
'generation stacked' = 'gen_stacked',
'generation yearly' = 'gen_year',
'power flows' = 'pf')),
conditionalPanel(
condition = "input.plot_type == 'gen_mix' || input.plot_type == 'res_single'",
uiOutput("zone_selection")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment