added example data
This commit is contained in:
parent
34aee9bc96
commit
be187e37f1
|
@ -6,3 +6,4 @@ inst/doc
|
||||||
data-raw/*.csv
|
data-raw/*.csv
|
||||||
node_modules
|
node_modules
|
||||||
docs
|
docs
|
||||||
|
data-raw/inputs/
|
||||||
|
|
31
R/data.R
31
R/data.R
|
@ -58,3 +58,34 @@
|
||||||
#' }
|
#' }
|
||||||
#' @source Wikipedia (\url{https://fr.wikipedia.org/wiki/Climat_de_Paris})
|
#' @source Wikipedia (\url{https://fr.wikipedia.org/wiki/Climat_de_Paris})
|
||||||
"climate_paris"
|
"climate_paris"
|
||||||
|
|
||||||
|
|
||||||
|
#' @title eco2mix data
|
||||||
|
#'
|
||||||
|
#' @description The dataset contains data about electricity consumption and production in France between 2012 and 2022.
|
||||||
|
#'
|
||||||
|
#' @format A data frame with 3,033 observations and 3 variables.
|
||||||
|
#'
|
||||||
|
#' @source Rte (Réseau et transport d'électricité) (\url{https://www.rte-france.com/eco2mix/} and \url{https://opendata.reseaux-energies.fr/})
|
||||||
|
"eco2mix"
|
||||||
|
|
||||||
|
|
||||||
|
#' @title Temperature data
|
||||||
|
#'
|
||||||
|
#' @description The dataset contains data about temperatures in France between 2018 and 2022.
|
||||||
|
#'
|
||||||
|
#' @format A data frame with 365 observations and 6 variables.
|
||||||
|
#'
|
||||||
|
#' @source Enedis (\url{https://data.enedis.fr/explore/dataset/donnees-de-temperature-et-de-pseudo-rayonnement/})
|
||||||
|
"temperatures"
|
||||||
|
|
||||||
|
|
||||||
|
#' @title Life expectancy data
|
||||||
|
#'
|
||||||
|
#' @description The dataset contains data about life expectancy in 1972 and 2007 for 10 countries.
|
||||||
|
#'
|
||||||
|
#' @format A data frame with 10 observations and 4 variables.
|
||||||
|
#'
|
||||||
|
#' @source gapminder package (\url{https://jennybc.github.io/gapminder/} and \url{https://www.gapminder.org/data/})
|
||||||
|
"life_expec"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# eCO2mix data
|
||||||
|
# https://www.rte-france.com/eco2mix
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Packages ----------------------------------------------------------------
|
||||||
|
|
||||||
|
library(data.table)
|
||||||
|
library(fasttime)
|
||||||
|
|
||||||
|
|
||||||
|
complete <- function(data, vars, fill = list()) {
|
||||||
|
data <- data[do.call(CJ, c(
|
||||||
|
lapply(
|
||||||
|
X = mget(vars),
|
||||||
|
FUN = function(var) {
|
||||||
|
if (inherits(var, "factor")) {
|
||||||
|
if (anyNA(var)) {
|
||||||
|
factor(c(levels(var), NA_character_), levels = levels(var), ordered = is.ordered(var))
|
||||||
|
} else {
|
||||||
|
factor(levels(var), levels = levels(var), ordered = is.ordered(var))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unique(var)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
list(sorted = FALSE)
|
||||||
|
)), on = vars]
|
||||||
|
if (length(fill) > 0 && all(nzchar(names(fill)))) {
|
||||||
|
for (fillvar in names(fill)) {
|
||||||
|
data[is.na(get(fillvar)), (fillvar) := fill[[fillvar]]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data[]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Download data -----------------------------------------------------------
|
||||||
|
|
||||||
|
# Source: https://odre.opendatasoft.com/explore/dataset/eco2mix-national-cons-def/
|
||||||
|
# and https://odre.opendatasoft.com/explore/dataset/eco2mix-national-tr
|
||||||
|
|
||||||
|
|
||||||
|
# Read & transform data ---------------------------------------------------
|
||||||
|
|
||||||
|
# eco2mix <- fread(file = "data-raw/inputs/eco2mix-national-cons-def.csv")
|
||||||
|
# eco2mix <- eco2mix[, c(5, 6, 9:17)]
|
||||||
|
# setnames(eco2mix, c("datetime", "consumption", "fuel", "coal", "gas", "nuclear", "wind", "solar", "hydraulic", "pumping", "bioenergies"))
|
||||||
|
|
||||||
|
eco2mix_tr <- fread(file = "data-raw/inputs/eco2mix-national-tr.csv")
|
||||||
|
eco2mix_tr <- eco2mix_tr[, c(5, 6, 9:17)]
|
||||||
|
setnames(eco2mix_tr, c("datetime", "consumption", "fuel", "coal", "gas", "nuclear", "wind", "solar", "hydraulic", "pumping", "bioenergies"))
|
||||||
|
|
||||||
|
eco2mix <- copy(eco2mix_tr)
|
||||||
|
# eco2mix <- rbind(eco2mix, eco2mix_tr)
|
||||||
|
|
||||||
|
eco2mix <- eco2mix[!is.na(consumption)]
|
||||||
|
eco2mix[, consumption := NULL]
|
||||||
|
# eco2mix[, date := as.Date(format(datetime, format = "%Y-%m-%d"))]
|
||||||
|
# eco2mix[, datetime := NULL]
|
||||||
|
# setcolorder(eco2mix, "date")
|
||||||
|
eco2mix <- eco2mix[minute(datetime) != 15]
|
||||||
|
eco2mix <- eco2mix[minute(datetime) != 45]
|
||||||
|
eco2mix <- eco2mix[datetime >= (max(datetime) - 24*60*60*7)]
|
||||||
|
eco2mix <- melt(
|
||||||
|
data = eco2mix,
|
||||||
|
id.vars = 1,
|
||||||
|
variable.name = "source",
|
||||||
|
value.name = "production",
|
||||||
|
na.rm = TRUE,
|
||||||
|
variable.factor = FALSE
|
||||||
|
)
|
||||||
|
eco2mix <- eco2mix[, list(production = round(mean(production))), by = list(datetime, source)]
|
||||||
|
eco2mix[, source := factor(
|
||||||
|
x = source,
|
||||||
|
levels = c("pumping", "wind", "solar", "nuclear", "hydraulic", "gas", "coal", "fuel", "bioenergies"),
|
||||||
|
ordered = TRUE
|
||||||
|
)]
|
||||||
|
eco2mix <- complete(eco2mix, c("datetime", "source"), list(production = 0))
|
||||||
|
setorder(eco2mix, source, datetime)
|
||||||
|
|
||||||
|
eco2mix[]
|
||||||
|
|
||||||
|
|
||||||
|
# Use data ----------------------------------------------------------------
|
||||||
|
|
||||||
|
setDF(eco2mix)
|
||||||
|
usethis::use_data(eco2mix, internal = FALSE, overwrite = TRUE, compress = "xz")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Test example ------------------------------------------------------------
|
||||||
|
|
||||||
|
apex(eco2mix[source == "consumption"], aes(date, production), type = "line")
|
||||||
|
|
||||||
|
# data("eco2mix", package = "apexcharter")
|
||||||
|
apex(eco2mix, aes(datetime, production, fill = source), type = "area") %>%
|
||||||
|
ax_chart(animations = list(enabled = FALSE), stacked = TRUE) %>%
|
||||||
|
ax_stroke(width = 1) %>%
|
||||||
|
ax_fill(opacity = 1, type = "solid") %>%
|
||||||
|
ax_tooltip(x = list(format = "dd MMM, HH:mm")) %>%
|
||||||
|
ax_yaxis(labels = list(formatter = format_num("~", suffix = "MW"))) %>%
|
||||||
|
ax_colors_manual(
|
||||||
|
list(
|
||||||
|
"bioenergies" = "#156956",
|
||||||
|
"fuel" = "#80549f",
|
||||||
|
"coal" = "#a68832",
|
||||||
|
"solar" = "#d66b0d",
|
||||||
|
"gas" = "#f20809",
|
||||||
|
"wind" = "#72cbb7",
|
||||||
|
"hydraulic" = "#2672b0",
|
||||||
|
"nuclear" = "#e4a701",
|
||||||
|
"pumping" = "#0e4269"
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
ax_labs(
|
||||||
|
title = "Electricity generation by sector in France",
|
||||||
|
subtitle = "Data from \u00e9CO\u2082mix"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
|
||||||
|
|
||||||
|
# Package -----------------------------------------------------------------
|
||||||
|
|
||||||
|
library(data.table)
|
||||||
|
library(gapminder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Data --------------------------------------------------------------------
|
||||||
|
|
||||||
|
life_expec <- as.data.table(gapminder::gapminder)
|
||||||
|
life_expec <- life_expec[year %in% c(1972, 2007), list(country, year, lifeExp)]
|
||||||
|
|
||||||
|
# life_expec <- life_expec[country %in% sample(unique(country), 10)]
|
||||||
|
life_expec <- life_expec[country %in% c("Botswana", "Ghana", "Iran", "Liberia", "Malaysia", "Mexico",
|
||||||
|
"Nigeria", "Pakistan", "Philippines", "Zambia")]
|
||||||
|
life_expec <- dcast(life_expec, country ~ year, value.var = "lifeExp")
|
||||||
|
life_expec[, type := fifelse(`1972` > `2007`, "decreased", "increased")]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Use data ----------------------------------------------------------------
|
||||||
|
|
||||||
|
setDF(life_expec)
|
||||||
|
usethis::use_data(life_expec, internal = FALSE, overwrite = TRUE, compress = "xz")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Test example ------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
pkgload::load_all()
|
||||||
|
|
||||||
|
apex(life_expec, aes(country, x = `1972`, xend = `2007`), type = "dumbbell") %>%
|
||||||
|
ax_plotOptions(
|
||||||
|
bar = bar_opts(
|
||||||
|
dumbbellColors = list(list("#3d85c6", "#fb6003"))
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
ax_colors("#BABABA") %>%
|
||||||
|
ax_labs(
|
||||||
|
title = "Life expectancy : 1972 vs. 2007",
|
||||||
|
subtitle = "Data from Gapminder dataset",
|
||||||
|
x = "Life expectancy at birth, in years"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
apex(life_expec, aes(country, x = `1972`, xend = `2007`, group = type), type = "dumbbell") %>%
|
||||||
|
ax_xaxis(type = "category", categories = unique(life_expec$country)) %>%
|
||||||
|
ax_plotOptions(
|
||||||
|
bar = bar_opts(
|
||||||
|
dumbbellColors = list(list("#3d85c6", "#fb6003"), list("#3d85c6", "#fb6003"))
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
ax_colors(c("#3d85c6", "#fb6003")) %>%
|
||||||
|
ax_labs(
|
||||||
|
title = "Life expectancy : 1972 vs. 2007",
|
||||||
|
subtitle = "Data from Gapminder dataset",
|
||||||
|
x = "Life expectancy at birth, in years"
|
||||||
|
)
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# temperature data for France
|
||||||
|
# https://data.enedis.fr/explore/dataset/donnees-de-temperature-et-de-pseudo-rayonnement
|
||||||
|
#
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# Packages ----------------------------------------------------------------
|
||||||
|
|
||||||
|
library(data.table)
|
||||||
|
library(fasttime)
|
||||||
|
|
||||||
|
|
||||||
|
# Data --------------------------------------------------------------------
|
||||||
|
|
||||||
|
temperatures <- fread(file = "data-raw/inputs/donnees-de-temperature-et-de-pseudo-rayonnement.csv")
|
||||||
|
temperatures <- temperatures[, c(6, 7, 8, 2)]
|
||||||
|
setnames(temperatures, c("year", "month", "day", "temperature"))
|
||||||
|
temperatures <- temperatures[year > 2017]
|
||||||
|
temperatures <- temperatures[, list(temperature = round(mean(temperature, na.rm = TRUE), 1)), by = c("year", "month", "day")]
|
||||||
|
temperatures <- dcast(data = temperatures, formula = month + day ~ year, value.var = "temperature")
|
||||||
|
temperatures <- temperatures[!(month == 2 & day == 29)]
|
||||||
|
|
||||||
|
temperatures[, low := do.call(pmin, c(as.list(.SD), na.rm = TRUE)), .SDcols = as.character(2018:2021)]
|
||||||
|
temperatures[, high := do.call(pmax, c(as.list(.SD), na.rm = TRUE)), .SDcols = as.character(2018:2021)]
|
||||||
|
temperatures[, average := rowMeans(.SD, na.rm = TRUE), .SDcols = as.character(2018:2021)]
|
||||||
|
temperatures[, (as.character(2018:2021)) := NULL]
|
||||||
|
# setnames(temperatures, "2022", "temperature")
|
||||||
|
|
||||||
|
temperatures[, date := as.Date("2022-01-01") + (seq_len(.N) - 1)]
|
||||||
|
temperatures[, (c("month", "day")) := NULL]
|
||||||
|
setcolorder(temperatures, "date")
|
||||||
|
|
||||||
|
temperatures[]
|
||||||
|
|
||||||
|
|
||||||
|
# Save --------------------------------------------------------------------
|
||||||
|
|
||||||
|
setDF(temperatures)
|
||||||
|
usethis::use_data(temperatures, internal = FALSE, overwrite = TRUE, compress = "xz")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Test example ------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
pkgload::load_all()
|
||||||
|
|
||||||
|
apex(temperatures, aes(x = date, ymin = low, ymax = high), type = "rangeArea", serie_name = "Low/High (2018-2021)") %>%
|
||||||
|
add_line(aes(date, `2023`)) %>%
|
||||||
|
ax_chart(animations = list(enabled = FALSE)) %>%
|
||||||
|
ax_yaxis(tickAmount = 7, labels = list(formatter = format_num("~", suffix = "°C"))) %>%
|
||||||
|
ax_colors(c("#8485854D", "#FF0000")) %>%
|
||||||
|
ax_stroke(width = c(1, 2)) %>%
|
||||||
|
ax_fill(opacity = 1, type = "solid") %>%
|
||||||
|
ax_labs(
|
||||||
|
title = "Temperatures in 2023 with range from 2018 to 2021",
|
||||||
|
subtitle = "Data from ENEDIS"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,19 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/data.R
|
||||||
|
\docType{data}
|
||||||
|
\name{eco2mix}
|
||||||
|
\alias{eco2mix}
|
||||||
|
\title{eco2mix data}
|
||||||
|
\format{
|
||||||
|
A data frame with 3,033 observations and 3 variables.
|
||||||
|
}
|
||||||
|
\source{
|
||||||
|
Rte (Réseau et transport d'électricité) (\url{https://www.rte-france.com/eco2mix/} and \url{https://opendata.reseaux-energies.fr/})
|
||||||
|
}
|
||||||
|
\usage{
|
||||||
|
eco2mix
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
The dataset contains data about electricity consumption and production in France between 2012 and 2022.
|
||||||
|
}
|
||||||
|
\keyword{datasets}
|
|
@ -0,0 +1,19 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/data.R
|
||||||
|
\docType{data}
|
||||||
|
\name{life_expec}
|
||||||
|
\alias{life_expec}
|
||||||
|
\title{Life expectancy data}
|
||||||
|
\format{
|
||||||
|
A data frame with 10 observations and 4 variables.
|
||||||
|
}
|
||||||
|
\source{
|
||||||
|
gapminder package (\url{https://jennybc.github.io/gapminder/} and \url{https://www.gapminder.org/data/})
|
||||||
|
}
|
||||||
|
\usage{
|
||||||
|
life_expec
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
The dataset contains data about life expectancy in 1972 and 2007 for 10 countries.
|
||||||
|
}
|
||||||
|
\keyword{datasets}
|
|
@ -0,0 +1,19 @@
|
||||||
|
% Generated by roxygen2: do not edit by hand
|
||||||
|
% Please edit documentation in R/data.R
|
||||||
|
\docType{data}
|
||||||
|
\name{temperatures}
|
||||||
|
\alias{temperatures}
|
||||||
|
\title{Temperature data}
|
||||||
|
\format{
|
||||||
|
A data frame with 365 observations and 6 variables.
|
||||||
|
}
|
||||||
|
\source{
|
||||||
|
Enedis (\url{https://data.enedis.fr/explore/dataset/donnees-de-temperature-et-de-pseudo-rayonnement/})
|
||||||
|
}
|
||||||
|
\usage{
|
||||||
|
temperatures
|
||||||
|
}
|
||||||
|
\description{
|
||||||
|
The dataset contains data about temperatures in France between 2018 and 2022.
|
||||||
|
}
|
||||||
|
\keyword{datasets}
|
Loading…
Reference in New Issue