library("ggplot2")
library("ggforce")
library("edm1")
library("smplot2")
library("shiny")
library("treemapify")
library("wesanderson")

Info graphs:

Les graphs sont rélisés en choisisant l’Allemagne et la France pour les années 2000 et début 2010

Info donnés:

Les données sont groupées par pays et un individu correspond à la concaténation des variables year et country.

pre_data <- read.table(file = "datas/owid-energy-data.csv",
             sep = ",", fill = TRUE, head = TRUE, quote = "\\")

pre_data <- pre_data[-grep_all(pattern_v = c("ASEAN", "Africa", "Asia",
                                  "Australia and New Zealand", "CIS", 
                                  "Central and South America",
                                  "Central America",
                                  "EU28", "Eastern Africa", "Eurasia", 
                                  "Europe", "European Union (27)", "G20",
                                  "G7", "Latin America and Caribbean", 
                                  "[Ll]ow", "Middle", "Non\\-", "OECD", "OPEC", "Persian",
                                  "U\\.S", "Wake"),
                            inpt_v = pre_data$country), ]

pre_data <- cbind("individual" = paste(pre_data$country, pre_data$year, sep = "_"), pre_data)
ref_vec <- c(
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

color_vec <- c(
  "oil_electricity" = "#80549f",
  "coal_electricity" = "#a68832",
  "solar_electricity" = "#d66b0d",
  "gas_electricity" = "#f20809",
  "wind_electricity" = "#72cbb7",
  "hydro_electricity" = "#2672b0",
  "nuclear_electricity" = "#e4a701",
  "biofuel_electricity" = "#156956",
  "other_renewable_exc_biofuel_electricity" = "#426915"
)

Type d’énergie utilisées pour générer de l’électricité par plusieurs pays pour une tranche d’années

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

data <- pre_data[, cur_vec]
vec_ids <- all_concat(c("France", "Germany"), c(2000:2012), sep = "_") 
cur_data <- data.frame("values" = unlist(data[match(table = data$individual, x = vec_ids), 4:ncol(data)]),
                       type = colnames(data)[4:ncol(data)])
cur_data <- sum_group2(inpt_datf = cur_data, col_grp = "type", col_to_add = "values")
cur_data <- cur_data[match(x = unique(cur_data$type), table = cur_data$type), ]
rownames(cur_data) <- c(1:nrow(cur_data))
ggplot(data = cur_data, mapping = aes(x = "", y = values, fill = type)) + 
  geom_bar(stat = "identity") +
  coord_polar("y", start = 0) +
  theme_minimal() +
  labs(title = "Type d'énergie utilisées pour générer de l'électricité\n par plusieurs pays entre 2000 et 2012"
  )

ggplot(data = cur_data, mapping = aes(y = reorder(type, values), x = values)) + 
  geom_bar(stat = "identity") +
  theme_minimal() +
  labs(title = "Type d'énergie utilisées pour générer de l'électricité\n par plusieurs pays entre 2000 et 2012"
  )

Pays choisis ayant généré le plus d’électricité de tel ou tel type pour une tranche d’année

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)


data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
vec_ids <- all_concat(countries_v, c(2000:2012), sep = "_") 
cur_data <- data[match(x = vec_ids, table = data$individual), ]
cur_energie_v <- c("biofuel_electricity", "gas_electricity", "solar_electricity")
sum_v <- c()
cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  sum_v <- c(sum_v, sum(cur_data[i, cur_col_v]))  
}
cur_data <- as.data.frame(cbind("country" = cur_data[, 2], "sum_energies" = sum_v))
cur_data$sum_energies <- as.numeric(cur_data$sum_energies)
cur_data <- sum_group1(inpt_datf = cur_data, col_grp = "country", col_to_add = "sum_energies")
cur_data <- cur_data[match(x = countries_v, table = cur_data$country), ]

ggplot(data = cur_data, mapping = aes(x = sum_energies, y = reorder(country, sum_energies))) + 
  geom_col() +
  theme_minimal() +
  labs(title = "Pays choisis ayant généré le plus d'électricité entre 2000 et 2012",
  x = "electricity twh",
  y = "country") 

Pays choisis ayant généré le moins d’électricité de tel ou tel type pour une tranche d’année

ggplot(data = cur_data, mapping = aes(x = sum_energies, y = reorder(country, -sum_energies))) + 
  geom_col() +
  theme_minimal() +
  labs(title = "Pays choisis ayant généré le moins d'électricité entre 2000 et 2012",
  x = "electricity twh",
  y = "country") 

Pays choisis ayant le plus grand volume de changement de consommation électrique de telle ou telle énergie sur une période choisie

cur_vec <- c("individual",
             "country",
             "year",
             "biofuel_cons_change_twh",
             "coal_cons_change_twh",
             "gas_cons_change_twh",
             "hydro_cons_change_twh",
             "nuclear_cons_change_twh",
             "oil_cons_change_twh",
             "other_renewables_cons_change_twh",
             "solar_cons_change_twh",
             "wind_cons_change_twh")

data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
vec_ids <- all_concat(countries_v, c(2004:2009), sep = "_")
cur_data <- data[match(x = vec_ids, table = data$individual), ]
sum_vec <- c()
cur_energie_v <- c(cur_vec[(match(x = "biofuel_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "gas_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "solar_electricity", table = ref_vec) + 3)])
cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  sum_vec <- c(sum_vec, sum(cur_data[i, cur_col_v]))
}
cur_data <- as.data.frame(cbind("country" = cur_data[, "country"], "sum_cons_change" = sum_vec))
cur_data$sum_cons_change <- as.numeric(cur_data$sum_cons_change)
cur_data <- sum_group1(inpt_datf = cur_data, col_grp = "country", col_to_add = "sum_cons_change")
cur_data <- cur_data[match(x = unique(countries_v), table = cur_data$country), ]
ggplot(data = cur_data, mapping = aes(x = sum_cons_change, y = reorder(country, sum_cons_change))) + 
  geom_col() +
  theme_minimal() +
  labs(title = "Pays choisis ayant le plus grand volume de changement de consommation\n électrique de telle ou telle énergie sur une période choisie", x = "différence d'énergie par rapport à t - 1", y = "country")

Pays choisis ayant le plus petit volume de changement de consommation électrique de telle ou telle énergie sur une période choisie

ggplot(data = cur_data, mapping = aes(x = sum_cons_change, y = reorder(country, -sum_cons_change))) + 
  geom_col() +
  theme_minimal() +
  labs(title = "Pays choisis ayant le plus petit volume de changement de consommation\n électrique de telle ou telle énergie sur une période choisie", x = "différence d'énergie par rapport à t - 1", y = "country")

Pays choisis ayant la plus grande part de changement de consommation électrique de telle ou telle énergie sur une période choisie

cur_vec <- c("individual",
             "country",
             "year",
             "biofuel_cons_change_pct",
             "coal_cons_change_pct",
             "gas_cons_change_pct",
             "hydro_cons_change_pct",
             "nuclear_cons_change_pct",
             "oil_cons_change_pct",
             "other_renewables_cons_change_pct",
             "solar_cons_change_pct",
             "wind_cons_change_pct")

data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
vec_ids <- all_concat(countries_v, c(2004:2009), sep = "_")
cur_data <- data[match(x = vec_ids, table = data$individual), ]
sum_vec <- c()
cur_energie_v <- c(cur_vec[(match(x = "biofuel_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "gas_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "solar_electricity", table = ref_vec) + 3)])
cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))

cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  sum_vec <- c(sum_vec, sum(cur_data[i, cur_col_v]))
}
cur_data <- as.data.frame(cbind("country" = cur_data[, "country"], "sum_cons_change" = sum_vec))
cur_data$sum_cons_change <- as.numeric(cur_data$sum_cons_change)
cur_data <- sum_group1(inpt_datf = cur_data, col_grp = "country", col_to_add = "sum_cons_change")
cur_data <- cur_data[match(x = unique(countries_v), table = cur_data$country), ]
ggplot(data = cur_data, mapping = aes(x = sum_cons_change, y = reorder(country, sum_cons_change))) + 
  geom_col() +
  theme_minimal(base_size = 11) +
  labs(title = "Pays choisis ayant la plus grande part de changement de consommation\n électrique des énergies choisies entre 2000 et 2012", 
       x = "somme différence d'énergie par rapport à t - 1 en %", 
       y = "country") 

Pays choisis ayant la plus petite part de changement de consommation électrique de telle ou telle énergie sur une période choisie

ggplot(data = cur_data, mapping = aes(x = sum_cons_change, y = reorder(country, -sum_cons_change))) + 
  geom_col() +
  theme_minimal() +
  labs(title = "Pays choisis ayant la plus petite part de changement de consommation\n électrique des énergies choisies entre 2000 et 2012", 
       x = "somme différence d'énergie par rapport à t - 1 en %", 
       y = "country") 

Evolution de la production électrique de telle ou telle énergie de pays choisis en twh

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)
data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
energies_v <- c("biofuel_electricity", "gas_electricity")
vec_ids <- all_concat(countries_v, c(2004:2009), sep = "_")
cur_data <- data[match(x = vec_ids, table = data$individual), ]
cur_sum <- c()
cur_col_v <- match(x = energies_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  cur_sum <- c(cur_sum, sum(cur_data[i, cur_col_v]))
}
cur_data <- as.data.frame(cbind(cur_data[, c("country", "year")], "values" = cur_sum))
cur_data$values <- as.numeric(cur_data$values)

version 1

ggplot(data = cur_data, mapping = aes(x = year, y = values, color = country, fill = country)) +
  geom_point() +
  geom_line() +
  geom_area(alpha = 0.4) +
  theme_minimal() +
  labs(title = "Evolution de la production électrique des énergies choisies\n de pays choisis en twh", x = "year", y = "différence d'énergie par rapport à t - 1 en %")

version 2

ggplot(data = cur_data, mapping = aes(x = year, y = values, fill = country)) +
  geom_area(alpha = 0.4) + 
  theme_minimal() +
  labs(title = "Evolution de la production électrique des énergies choisies\n de pays choisis en twh", x = "year", y = "différence d'énergie par rapport à t - 1 en %")

Evolution de la différence de consommation électrique de telle ou telle énergie des pays choisis au sein de la même année, en pourcentage

cur_vec <- c("individual",
             "country",
             "year",
             "biofuel_cons_change_pct",
             "coal_cons_change_pct",
             "gas_cons_change_pct",
             "hydro_cons_change_pct",
             "nuclear_cons_change_pct",
             "oil_cons_change_pct",
             "other_renewables_cons_change_pct",
             "solar_cons_change_pct",
             "wind_cons_change_pct")

data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
vec_ids <- all_concat(countries_v, c(2004:2009), sep = "_")
cur_data <- data[match(x = vec_ids, table = data$individual), ]
sum_vec <- c()
cur_energie_v <- c(cur_vec[(match(x = "nuclear_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "biofuel_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "coal_electricity", table = ref_vec) + 3)])
cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  sum_vec <- c(sum_vec, sum(cur_data[i, cur_col_v]))
}
cur_data <- as.data.frame(cbind(cur_data[, c("country", "year")], "sum_cons_change" = sum_vec))
cur_data$sum_cons_change <- as.numeric(cur_data$sum_cons_change)

version 1

ggplot(data = cur_data) + 
  geom_point(mapping = aes(color = country)) + 
  geom_line(mapping = aes(color = country)) +
  geom_area(mapping = aes(fill = country), alpha = 0.35) +
  aes(x = year, y = sum_cons_change) +
  theme_minimal() +
  labs(title = "Evolution de la différence de consommation électrique\n des énergies choisies des pays choisis en pourcentage",
       x = "year",
       y = "Pourcentage d'électricité consommé comparé à l'année précédente")

version 2

ggplot(data = cur_data, mapping = aes(x = year, y = sum_cons_change, fill = country)) + 
  geom_area(alpha = 0.45) +
  theme_minimal() +
  labs(title = "Evolution de la différence de consommation électrique\n des énergies choisies des pays choisis en pourcentage",
       x = "year",
       y = "Pourcentage d'électricité consommé comparé à l'année précédente")

Evolution de la différence de consommation électrique de telle ou telle énergie des pays choisis au sein de la même année comparé à leur production interne, en pourcentage

ref_vec <- c(
             "hydro_electricity",
             "nuclear_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

cur_vec <- c("individual",
             "country",
             "year",
             "hydro_cons_change_pct",
             "nuclear_cons_change_pct",
             "other_renewables_cons_change_pct",
             "solar_cons_change_pct",
             "wind_cons_change_pct")

data <- pre_data[, cur_vec]
countries_v <- c("France", "Germany")
vec_ids <- all_concat(countries_v, c(2004:2009), sep = "_")
cur_data <- data[match(x = vec_ids, table = data$individual), ]
sum_vec <- c()
cur_energie_v <- c(cur_vec[(match(x = "nuclear_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "hydro_electricity", table = ref_vec) + 3)], 
                   cur_vec[(match(x = "solar_electricity", table = ref_vec) + 3)])
cur_col_v <- match(x = cur_energie_v, table = colnames(cur_data))
for (i in 1:nrow(cur_data)){
  sum_vec <- c(sum_vec, sum(cur_data[i, cur_col_v]))
}
cur_data <- as.data.frame(cbind(cur_data[, c("country", "year")], "sum_cons_change" = sum_vec))
cur_data$sum_cons_change <- as.numeric(cur_data$sum_cons_change)

version 1

ggplot(data = cur_data) + 
  geom_line(aes(color = country)) +
  geom_point(aes(color = country)) +
  geom_area(mapping = aes(fill = country), alpha = 0.35, stat = "identity") +
  aes(x = year, y = sum_cons_change) +
  theme_minimal() +
  labs(title = "Evolution de la différence de consommation électrique des énergies choisies\n produites en interne des pays choisis en pourcentage",
       x = "year",
       y = "Pourcentage d'électricité consommé comparé à l'année précédente")

version 2

ggplot(data = cur_data, mapping = aes(x = year, y = sum_cons_change, fill = country)) + 
  geom_area(alpha = 0.45) +
  theme_minimal() +
  labs(title = "Evolution de la différence de consommation électrique des énergies choisies\n produites en interne des pays choisis en pourcentage",
       x = "year",
       y = "Pourcentage d'électricité consommé comparé à l'année précédente")

Slope Chart (scalé)

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

data <- pre_data[, cur_vec]
cur_data <- data[match(x = c("France_1995", "France_2023"),
                   table = data$individual), ]
colnames(cur_data)[4:ncol(data)] <- paste("twh_cons", colnames(data)[4:ncol(data)], sep = "-")
cur_data <- edm_pivot_longer2(inpt_datf = cur_data,
                          col_vars = c(4:ncol(cur_data)),
                          col_vars_to = "energy_source")
cur_data <- cur_data[, 3:ncol(cur_data)]

#cur_data
#cur_vec <- c("blue", "red", "yellow", "purple", "orange", "pink", "black", "green", "grey")
#unique(cur_data$energy_source)
#names(cur_vec) <- unique(cur_data$energy_source)
#ggplot(data = cur_data, mapping = aes(x = year, y = twh_cons, fill = energy_source)) +
#  sm_slope(group = energy_source, labels = c("1995", "2023")) +
#  scale_color_manual(name = "Legend", 
#                     breaks = unique(cur_data$energy_source),
#                     values = cur_vec)

cur_data$twh_cons <- as.numeric(cur_data$twh_cons)

ggplot(data = cur_data, mapping = aes(x = year, 
                                      y = twh_cons,
                                      group = energy_source,
                                      color = energy_source)) +
  geom_line() +
  geom_point() +
  theme_minimal() +
  theme(legend.position = "bottom") +
  scale_y_continuous(trans = "log2")
## Warning in scale_y_continuous(trans = "log2"): log-2 transformation introduced infinite values.
## log-2 transformation introduced infinite values.

cur_data2 <- edm_pivot_series(inpt_datf = cur_data, 
                             time_col = "year", 
                             col_v = "twh_cons") 
#
#ggplot(data = cur_data, mapping = aes(x = "1995",
#                                      xend = "2023",
#                                      y = twh_cons_1995, 
#                                      yend = twh_cons_2023,
#                                      #fill = energy_source,
#                                      group = energy_source)) +
#  geom_line() 

Slope Chart (non scalé)

ggplot(data = cur_data, mapping = aes(x = year, 
                                      y = twh_cons,
                                      group = energy_source,
                                      color = energy_source)) +
  geom_line() +
  geom_point() +
  theme_minimal() +
  theme(legend.position = "bottom") 

Dumbell graph

cur_data2$twh_cons_1995 <- as.numeric(cur_data2$twh_cons_1995)
cur_data2$twh_cons_2023 <- as.numeric(cur_data2$twh_cons_2023)

#ggplot(data = cur_data2) +
#  geom_segment(mapping = aes(y = energy_source, 
#                             x = twh_cons_1995, 
#                             xend = twh_cons_2023)) +
#  geom_point(aes(
#                 y = energy_source,
#                 x = twh_cons_1995),
#            size = 4
#            ) +
#  geom_point(aes( 
#                 y = energy_source,
#                 x = twh_cons_2023,
#                 ),
#             shape = 17,
#             size = 4
#             ) +
#  theme_minimal() +
#  labs(x = "twh_cons") +
#  theme(legend.position = "bottom") 

cur_data$twh_cons <- as.numeric(cur_data$twh_cons)

ggplot(data = cur_data, mapping = aes(x = twh_cons, 
                                      y = energy_source, 
                                      group = energy_source
                                      )) +
  geom_line() +
  geom_point(mapping = aes(shape = year), size = 3) +
  theme_minimal() + 
  theme(legend.position = "bottom")

Cursor graph

cur_data <- pre_data[, c("low_carbon_share_elec", "fossil_share_elec", "individual")]
#sum(cur_data[cur_data$individual == "France_2012", 1:2])
cur_data <- as.numeric(cur_data[cur_data$individual == "France_2012", 1:2])
cur_data <- data.frame("type" = c("low_carbon", "high_carbon"), 
                   "percentage" = c(cur_data[1], cur_data[2]) / 100,
                   "start" = c(0, cur_data[1] / 100 * pi),
                   "end" = c(cur_data[1] / 100 * pi, pi)
)

ggplot(data = cur_data) +
  geom_arc_bar(
    mapping = aes(
      x0 = 1,
      y0 = 1,
      fill = type,
      start = start - pi / 2,
      end = end - pi / 2,
      r0 = 0.75,
      r = 1
    )
  ) +
  theme_minimal() +
  theme(legend.position = "bottom")

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

cur_data <- pre_data[, cur_vec] 
cur_data <- cur_data[cur_data$year == "2012", ]
tot_v <- c()
for (i in 1:nrow(cur_data)){
  tot_v <- c(tot_v, sum(as.numeric(cur_data[i, 4:ncol(cur_data)])))
}
cur_data <- as.data.frame(cbind(cur_data, "tot" = tot_v))
cur_data <- cur_data[-grep(pattern = TRUE, is.na(cur_data$tot)), ]
cur_med <- median(cur_data$tot)
cur_mean <- mean(cur_data$tot)
cur_max <- max(cur_data$tot)
cur_data2 <- cur_data[cur_data$country == "France", ]

ggplot(data = cur_data2, 
       mapping = aes(x = tot, 
                     y = country, 
                     width = 0.1)) +
  geom_col() +
  geom_vline(aes(xintercept = cur_med, color = "median"), linetype = "dashed", linewidth = 0.5) +
  geom_vline(aes(xintercept = cur_mean, color = "mean"), linetype = "dashed", linewidth = 0.5) +
  geom_vline(aes(xintercept = cur_max, color = "max"), linetype = "dashed", linewidth = 0.5) +
  scale_color_manual(values = c("red", "black", "blue")) +
  scale_x_continuous(trans = "log10") +
  theme_minimal() +
  theme(legend.position = "bottom") +
  labs(colour = "")

Tree Map (couleur par rapport à la valeur)

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

cur_data <- pre_data[, cur_vec]
cur_data <- cur_data[cur_data$individual == "France_2012", ]
colnames(cur_data)[4:ncol(cur_data)] <- paste("twh_cons", colnames(cur_data)[4:ncol(cur_data)], sep = "-") 
cur_data <- cur_data[, c(2, 4:ncol(cur_data))]
cur_data
##      country twh_cons-biofuel_electricity twh_cons-coal_electricity
## 7492  France                          5.3                     21.46
##      twh_cons-gas_electricity twh_cons-hydro_electricity
## 7492                    22.75                      59.83
##      twh_cons-nuclear_electricity twh_cons-oil_electricity
## 7492                       425.41                    12.71
##      twh_cons-other_renewable_exc_biofuel_electricity
## 7492                                             0.51
##      twh_cons-solar_electricity twh_cons-wind_electricity
## 7492                       4.43                     15.18
str(cur_data)
## 'data.frame':    1 obs. of  10 variables:
##  $ country                                         : chr "France"
##  $ twh_cons-biofuel_electricity                    : num 5.3
##  $ twh_cons-coal_electricity                       : num 21.5
##  $ twh_cons-gas_electricity                        : num 22.8
##  $ twh_cons-hydro_electricity                      : num 59.8
##  $ twh_cons-nuclear_electricity                    : num 425
##  $ twh_cons-oil_electricity                        : num 12.7
##  $ twh_cons-other_renewable_exc_biofuel_electricity: num 0.51
##  $ twh_cons-solar_electricity                      : num 4.43
##  $ twh_cons-wind_electricity                       : num 15.2
write.table(x = cur_data, file = "data.csv", sep = ",")

cur_data <- edm_pivot_longer1(inpt_datf = cur_data,
                              col_vars = c(2:ncol(cur_data)),
                              col_vars_to = "type")


cur_data$twh_cons <- as.numeric(cur_data$twh_cons) 
ggplot(data = cur_data, 
       mapping = aes(
                     fill = twh_cons,
                     area = twh_cons,
                     label = type
                     )) +
  geom_treemap() +
  geom_treemap_text(color = "white", place = "center", size = 15) +
  scale_fill_gradient(high = "#501569", low = "DarkRed")

Tree Map (couleur par rapport au type d’énergie)

ggplot(data = cur_data, 
       mapping = aes(
                     fill = type,
                     area = twh_cons,
                     label = twh_cons
                     )) +
  geom_treemap() +
  geom_treemap_text(color = "black", place = "center", size = 15) +
  scale_fill_manual(values = color_vec)

Barchart mix energetiqu un pays une année

col_convertr <- function(inpt_datf){
  for (i in 1:ncol(inpt_datf)){
    if (all(mapply(function(x) return(can_be_num(x)), inpt_datf[, i]))){
      inpt_datf[, i] <- as.numeric(inpt_datf[, i]) 
    }
  }
  return(inpt_datf)
}

cur_vec <- c("individual",
             "country", 
             "year", 
             "biofuel_electricity",
             "coal_electricity",
             "gas_electricity",
             "hydro_electricity",
             "nuclear_electricity",
             "oil_electricity",
             "other_renewable_exc_biofuel_electricity",
             "solar_electricity",
             "wind_electricity"
)

cur_data <- pre_data[, cur_vec]
cur_data <- cur_data[match(x = "France_2012", table = cur_data$individual), 
                     c(2, 4:ncol(cur_data))]

colnames(cur_data)[2:ncol(cur_data)] <- paste("twh_cons", colnames(cur_data)[2:ncol(cur_data)], sep = "-") 

cur_data <- col_convertr(edm_pivot_longer1(inpt_datf = cur_data,
                              col_vars = c(2:ncol(cur_data)),
                              col_vars_to = "type"))

ggplot(data = cur_data, 
       mapping = aes(x = twh_cons, 
                     y = reorder(type, twh_cons),
                     fill = type)) +
  geom_col() +
  scale_fill_manual(values = color_vec) +
  theme_minimal() +
  theme(legend.position = "bottom") 

Pie Chart mix energétique un pays une année

reorder(as.vector(cur_data$twh_cons), 
        as.vector(cur_data$twh_cons))
## [1] 5.3    21.46  22.75  59.83  425.41 12.71  0.51   4.43   15.18 
## attr(,"scores")
##   0.51   4.43    5.3  12.71  15.18  21.46  22.75  59.83 425.41 
##   0.51   4.43   5.30  12.71  15.18  21.46  22.75  59.83 425.41 
## Levels: 0.51 4.43 5.3 12.71 15.18 21.46 22.75 59.83 425.41
ggplot(data = cur_data, mapping = aes(fill = reorder(type, twh_cons), y = "", x = twh_cons)) + 
  geom_col() + 
  coord_polar(theta = "x", start = 0) +
  scale_fill_manual(values = color_vec) +
  theme(legend.position = "bottom")