# ------------------------------------------------------------------------
#
# Title : Example RTE
# By : VP
# Date : samedi 05/08/2017
#
# ------------------------------------------------------------------------
# Packages ----------------------------------------------------------------
library( "billboarder" )
# Datas -------------------------------------------------------------------
data("prod_par_filiere")
data("cdc_prod_filiere")
data("equilibre_mensuel")
# Barcharts ---------------------------------------------------------------
# Simple
billboarder() %>%
bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique")], color = "#102246") %>%
bb_y_grid(show = TRUE) %>%
bb_y_axis(tick = list(format = suffix("TWh")),
label = list(text = "production (in terawatt-hours)", position = "outer-top")) %>%
bb_legend(show = FALSE) %>%
bb_labs(title = "French hydraulic production",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# Dodge
billboarder() %>%
bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique", "prod_eolien", "prod_solaire")]) %>%
bb_data(names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar")) %>%
bb_y_grid(show = TRUE) %>%
bb_y_axis(tick = list(format = suffix("TWh")),
label = list(text = "production (in terawatt-hours)", position = "outer-top")) %>%
bb_legend(position = "inset", inset = list(anchor = "top-right")) %>%
bb_labs(title = "Renewable energy production",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# Stacked
billboarder() %>%
bb_barchart(data = prod_par_filiere[, c("annee", "prod_hydraulique", "prod_eolien", "prod_solaire")], stacked = TRUE) %>%
bb_data(names = list(prod_hydraulique = "Hydraulic", prod_eolien = "Wind", prod_solaire = "Solar"), labels = TRUE) %>%
bb_colors_manual("prod_eolien" = "#41AB5D", "prod_hydraulique" = "#4292C6", "prod_solaire" = "#FEB24C") %>%
bb_y_grid(show = TRUE) %>%
bb_y_axis(tick = list(format = suffix("TWh")),
label = list(text = "production (in terawatt-hours)", position = "outer-top")) %>%
bb_legend(position = "right") %>%
bb_labs(title = "Renewable energy production",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# production sources
prod_par_filiere_l <- reshape2::melt(data = prod_par_filiere)
prod_par_filiere_l <- prod_par_filiere_l[with(prod_par_filiere_l, annee == "2016" & variable != "prod_total"), 2:3]
prod_par_filiere_l <- prod_par_filiere_l[order(prod_par_filiere_l$value), ]
billboarder() %>%
bb_barchart(data = prod_par_filiere_l) %>%
bb_y_grid(show = TRUE) %>%
bb_legend(show = FALSE) %>%
bb_x_axis(categories = prod_par_filiere_l$variable, fit = FALSE) %>%
bb_labs(title = "French electricity generation by branch in 2016",
y = "production (in terawatt-hours)",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# Piecharts ---------------------------------------------------------------
nuclear2016 <- data.frame(
sources = c("Nuclear", "Other"),
production = c(
prod_par_filiere$prod_nucleaire[prod_par_filiere$annee == "2016"],
prod_par_filiere$prod_total[prod_par_filiere$annee == "2016"] -
prod_par_filiere$prod_nucleaire[prod_par_filiere$annee == "2016"]
)
)
billboarder() %>%
bb_piechart(data = nuclear2016) %>%
bb_labs(title = "Share of nuclear power in France in 2016",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# Linecharts --------------------------------------------------------------
billboarder() %>%
bb_linechart(data = rnorm(20))
billboarder() %>%
bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_eolien")]) %>%
bb_x_axis(tick = list(format = "%H:%M", fit = FALSE))
library("suncalc")
sun <- getSunlightTimes(date = as.Date("2017-06-12"), lat = 48.86, lon = 2.34, tz = "CET")
billboarder() %>%
bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_solaire")]) %>%
bb_x_axis(tick = list(format = "%H:%M", fit = FALSE)) %>%
bb_y_axis(min = 0, padding = 0) %>%
bb_regions(
list(
start = as.numeric(cdc_prod_filiere$date_heure[1]) * 1000,
end = as.numeric(sun$sunrise)*1000
),
list(
start = as.numeric(sun$sunset) * 1000,
end = as.numeric(cdc_prod_filiere$date_heure[48]) * 1000
)
) %>%
bb_x_grid(
lines = list(
list(value = as.numeric(sun$sunrise)*1000, text = "sunrise"),
list(value = as.numeric(sun$sunset)*1000, text = "sunset")
)
) %>%
bb_labs(title = "Solar production (2017-06-12)",
y = "In megawatt (MW)",
caption = "Data source: RTE (https://opendata.rte-france.com)")
billboarder() %>%
bb_linechart(data = cdc_prod_filiere[, c("date_heure", "prod_eolien", "prod_hydraulique", "prod_solaire")], type = "spline") %>%
bb_y_axis(min = 0, padding = 0)
billboarder() %>%
bb_linechart(
data = cdc_prod_filiere[, c("date_heure", "prod_eolien", "prod_hydraulique", "prod_solaire")],
type = "area"
) %>%
bb_data(
groups = list(list("prod_eolien", "prod_hydraulique", "prod_solaire")),
names = list("prod_eolien" = "Wind", "prod_hydraulique" = "Hydraulic", "prod_solaire" = "Solar")
) %>%
bb_legend(position = "inset", inset = list(anchor = "top-right")) %>%
bb_colors_manual("prod_eolien" = "#238443", "prod_hydraulique" = "#225EA8", "prod_solaire" = "#FEB24C", opacity = 0.8) %>%
bb_y_axis(min = 0, padding = 0) %>%
bb_labs(title = "Renewable energy production (2017-06-12)",
y = "In megawatt (MW)",
caption = "Data source: RTE (https://opendata.rte-france.com)")
# vs
billboarder() %>%
bb_linechart(
data = cdc_prod_filiere[, c("date_heure", "prod_eolien", "prod_hydraulique", "prod_solaire")],
type = "area"
) %>%
bb_data(
groups = list(list("prod_eolien", "prod_hydraulique", "prod_solaire")),
colors = list("prod_eolien" = "#238443", "prod_hydraulique" = "#225EA8", "prod_solaire" = "#FEB24C"),
names = list("prod_eolien" = "Wind", "prod_hydraulique" = "Hydraulic", "prod_solaire" = "Solar")
) %>%
bb_y_axis(min = 0, padding = 0)
billboarder() %>%
bb_linechart(
data = equilibre_mensuel[, c("date", "consommation", "production")],
type = "spline"
) %>%
bb_x_axis(tick = list(format = "%Y-%m", fit = FALSE)) %>%
bb_x_grid(show = TRUE) %>%
bb_y_grid(show = TRUE) %>%
bb_colors_manual("consommation" = "firebrick", "production" = "forestgreen") %>%
bb_legend(position = "right") %>%
bb_subchart(show = TRUE, size = list(height = 30)) %>%
bb_labs(title = "Monthly electricity consumption and production in France (2007 - 2017)",
y = "In megawatt (MW)",
caption = "Data source: RTE (https://opendata.rte-france.com)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.