__STYLES__
This notebook project in R Markdown is about worldwide data on hydro, wind, solar, biofuel, and geothermal energy. The data is in % of equivalent primary energy derived from renewable resources, and energy in TeraWatts per hour (TWh).
The project includes some of the basic R functions to process, clean, analyze and visualize data.
For this project, the objective is to analyze the percentage of equivalent primary energy from renewable energies that each country has through the time, and the energy in TWh produced by country, continent and globally.
The datasets were already prepared and cleaned in Excel, so all the data has the right format, match and it could be joined together.
The notebook and the modified dataset can be found in Kaggle.
library(tidyverse)
library(skimr)
library(janitor)
library(dplyr)
library(ggplot2)
library(readxl)
library(lubridate)
library(knitr)
library(kableExtra)
renewable_energy <- read_csv("/kaggle/input/pre-processed-renewable-energy/01 renewable-share-energy.csv")
renewable_electricity <- read_csv("/kaggle/input/renewable-energy-world-wide-19652022/03 modern-renewable-prod.csv")
head(renewable_energy) --% of equivalent primary energy
head(renewable_electricity) --energy in TWh
The "Code" column is not useful, so it can be deleted in both tables:
# Remove the "Code" column
renewable_energy <- renewable_energy %>%
select(-Code)
renewable_electricity <- renewable_electricity %>%
select(-Code)
head(renewable_energy)
head(renewable_electricity)
Finally, for the analysis of the second dataset it maybe useful to separate the data into two tables: one for countries and one for continents:
# Create a dataframe with all the countries
countries_df <- renewable_electricity %>%
filter(!Entity %in% c("Africa", "Africa (BP)", "Eastern Africa (BP)", "Middle Africa (BP)", "Asia", "Asia Pacific (BP)", "CIS (BP)",
"Europe", "Europe (BP)", "European Union (27)", "North America", "North America (BP)",
"Central America (BP)", "OECD (BP)", "South and Central America (BP)", "Upper-middle-income countries",
"South America", "Oceania", "High-income countries", "Lower-middle-income countries",
"Middle East (BP)", "Non-OECD (BP)", "Western Africa (BP)", "G20 (Ember)", "Asia (Ember)",
"OECD (Ember)", "G7 (Ember)", "Europe (Ember)", "North America (Ember)",
"European Union (27) (Ember)", "Latin America and Caribbean (Ember)", "Africa (Ember)",
"Low-income countries", "Oceania (Ember)", "World"))
# Create a dataframe with all the continents
continents_df <- renewable_electricity %>%
filter(Entity %in% c("Africa", "Asia", "Europe", "North America", "Central America (BP)", "South America", "Oceania", "World"))
# Combine the dataframes into a list
split_data <- list(Countries = countries_df, Continents = continents_df)
# Alternatively, you can use a named list
split_data_named <- list(Countries = countries_df, Continents = continents_df)
# Access the separate dataframes
countries_ele <- split_data$Countries
continents_ele <- split_data$Continents
Starting with the analysis of the first dataset with the percentage of equivalent primary energy that is generated from renewable resources for each country or region; in other words, the percentage of primary energy that is being covered by renewable sources. To find the top 10 countries with the highest growth from 1990 to 2020, the difference between the last and the first year is calculated and then the 10 countries with the highest growth are found:
# Filter the data for years greater than or equal to 1990
renewable_energy_1990_2021 <- renewable_energy %>%
filter(Year >= 1990 & Year <= 2021)
# Calculate the growth for each country or entity
renewable_energy_1990_2021 <- renewable_energy_1990_2021 %>%
group_by(Entity) %>%
mutate(Growth_Renewables = last(`Renewables (% equivalent primary energy)`) - first(`Renewables (% equivalent primary energy)`))
# Find the top 10 countries with the biggest growth
top_10_energy <- renewable_energy_1990_2021 %>%
group_by(Entity) %>%
summarise(Total_Growth = last(Growth_Renewables)) %>%
top_n(10, Total_Growth) %>%
arrange(desc(Total_Growth))
# Display the results
cat("Top 10 countries with the biggest growth in equivalent renewable energy :\n")
knitr::kable(top_10_energy, format = "markdown", caption = "Top 10 Countries")
From the table, Denmark increased by 37.98% that percentage of equivalent primary energy that is derived from renewable sources and it is the country with the biggest growth from 1990 to 2021.
# Create a vector of continent names
continents <- c("Africa", "Asia", "Europe", "North America", "Central America (BP)", "South America", "Oceania", "World")
# Filter the data for years between 1990 and 2021 and for continent names
renewable_energy_continents <- renewable_energy %>%
filter(Year >= 1990 & Year <= 2021, Entity %in% continents)
# Calculate the difference between the last and first year for each continent from 1990 to 2021
renewable_energy_continents <- renewable_energy_continents %>%
group_by(Entity) %>%
summarise(Total_Growth = last(`Renewables (% equivalent primary energy)`) - first(`Renewables (% equivalent primary energy)`))
# Sort continents in descending order based on the difference in renewable energy generation
sorted_continents <- renewable_energy_continents %>%
arrange(desc(Total_Growth))
# Display the results
cat("Growth of percentage of equivalent primary energy derived from renewable sources by continent :\n")
knitr::kable(sorted_continents, format = "markdown", caption = "% equivalente primary energy growth by continents")
Since America is divided into three regions and the percentages are not additive quantities, it is only possible to know the growth for North, South and Central America individually. Considering that, Europe is the continent with the highest increase in % of equivalent primary energy derived from renewable sources, it has an increase of 9.62% from 1990 to 2020. Compared to that, the whole world only had a 6.29% of growth in that period of time.
In this section it is analyzed the capacity that the countries have in electricity generation in 2021 that comes from renewable resources, and then the top 10 countries with the highest capacity is found:
# Filter the data for the year 2021
countries_electricity_2021 <- countries_ele %>%
filter(Year == 2021)
# Calculate the total renewable electricity generation for each country in 2021
countries_electricity_total <- countries_electricity_2021 %>%
mutate(TotalRenewables = `Electricity from wind (TWh)` + `Electricity from hydro (TWh)` +
`Electricity from solar (TWh)` + `Other renewables including bioenergy (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalGeneration = sum(TotalRenewables, na.rm = TRUE)) %>%
arrange(desc(TotalGeneration)) # Sort in descending order
# Select the top 10 countries
top_10_countries <- countries_electricity_total %>%
top_n(10, TotalGeneration)
# Print the top 10 countries with their total renewable generation for 2021 using kable
knitr::kable(top_10_countries, format = "markdown", caption = "Top 10 Countries with the Highest Total Renewable Electricity Generation in 2021")
China is the country with the highest Renewable Energy capacity in electricity generation, with 2453 TWh, almost three times the capacity that the United States has.
The top 10 countries with the highest share in hydro, wind, solar and other reosurces in 2021:
# Filter the data for the year 2021
countries_electricity_2021 <- countries_ele %>%
filter(Year == 2021)
# Calculate the wind renewable electricity generation for each country in 2021
countries_electricity_wind <- countries_electricity_2021 %>%
mutate(wind = `Electricity from wind (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalWind = sum(wind, na.rm = TRUE)) %>%
arrange(desc(TotalWind)) # Sort in descending order
# Calculate the hydro renewable electricity generation for each country in 2021
countries_electricity_hydro <- countries_electricity_2021 %>%
mutate(hydro =`Electricity from hydro (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalHydro = sum(hydro, na.rm = TRUE)) %>%
arrange(desc(TotalHydro)) # Sort in descending order
# Calculate the solar renewable electricity generation for each country in 2021
countries_electricity_solar <- countries_electricity_2021 %>%
mutate(solar = `Electricity from solar (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalSolar = sum(solar, na.rm = TRUE)) %>%
arrange(desc(TotalSolar)) # Sort in descending order
# Calculate the other renewable electricity generation for each country in 2021
countries_electricity_other <- countries_electricity_2021 %>%
mutate(other = `Other renewables including bioenergy (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalOther = sum(other, na.rm = TRUE)) %>%
arrange(desc(TotalOther)) # Sort in descending order
# Select the top 10 countries
top_10_countries_wind <- countries_electricity_wind %>%
top_n(10, TotalWind)
top_10_countries_hydro <- countries_electricity_hydro %>%
top_n(10, TotalHydro)
top_10_countries_solar <- countries_electricity_solar %>%
top_n(10, TotalSolar)
top_10_countries_other <- countries_electricity_other %>%
top_n(10, TotalOther)
# Print the top 10 countries with their total renewable generation for 2021
kable(top_10_countries_wind, format = "markdown", caption = "Top 10 Countries with the Highest Electricity Generation (in TWh) by Wind in 2021")
kable(top_10_countries_hydro, format = "markdown", caption = "Top 10 Countries with the Highest Electricity Generation (in TWh) by Hydro in 2021")
kable(top_10_countries_solar, format = "markdown", caption = "Top 10 Countries with the Highest Electricity Generation (in TWh) by Solar in 2021")
kable(top_10_countries_other, format = "markdown", caption = "Top 10 Countries with the Highest Electricity Generation (in TWh) by other resources in 2021")
China is clearly the country with the highest capacity in each category in 2021.
The next step is to find the countries with the highest growth in Total Renewable Capacity from 1990 to 2021. The highest growth can be measured in the increase of TWh or as a percentage of the Total Renewable Capacity that the countries had in 1990:
# Filter the data for the years 1990 and 2021
countries_capacity <- countries_ele %>%
filter(Year %in% c(1990, 2021))
# Calculate the Total Capacity for each country in 1990 and 2021
countries_capacity <- countries_capacity %>%
group_by(Entity, Year) %>%
summarise(TotalCapacity = sum(`Electricity from wind (TWh)`,
`Electricity from hydro (TWh)`,
`Electricity from solar (TWh)`,
`Other renewables including bioenergy (TWh)`,
na.rm = TRUE))
# Pivot the data to have 1990 and 2021 as columns
countries_capacity_pivot <- countries_capacity %>%
pivot_wider(names_from = Year, values_from = TotalCapacity)
# Calculate the difference in Total Capacity between 2021 and 1990
countries_capacity_pivot <- countries_capacity_pivot %>%
mutate(TotalGrowth = `2021` - `1990`)
# Select the Top 10 Countries with the highest difference in Total Capacity
top_10_growth <- countries_capacity_pivot %>%
arrange(desc(TotalGrowth)) %>%
head(10)
# Calculate the percentage growth for each country
top_10_growth_perc <- top_10_growth %>%
mutate(PercentageGrowth = (`2021` / `1990`) * 100)
# Print the top 10 countries with the highest growth percentage in Total Capacity
kable(top_10_growth_perc, format = "markdown", caption = "Top 10 Countries with the Highest Growth Percentage in Total Electricity Generation from 1990 to 2021.")
According to the results, China increased it's total capacity by 2325.72 TWh, more than 4 times the total growth of the United States in the second place. But in percentage China it's not the first place, the United Kingdom increased it's total capacity from 5.8 TWh to 122.2 TWh, giving a growth of 2099% in that period of time, and Vietnam also had a hugh increased of 1941%.
In this case, as the data is in TWh, North, South and Central America can be merged into America:
# Filter the data for the years 1990 and 2021
continents_capacity <- continents_ele %>%
filter(Year %in% c(1990, 2021))
# Calculate the Total Capacity for each continent in 1990 and 2021
continents_capacity <- continents_capacity %>%
group_by(Entity, Year) %>%
summarise(TotalCapacity = sum(`Electricity from wind (TWh)`,
`Electricity from hydro (TWh)`,
`Electricity from solar (TWh)`,
`Other renewables including bioenergy (TWh)`,
na.rm = TRUE))
# Merge North, South, and Central America into "America"
continents_capacity_merged <- continents_capacity %>%
mutate(Entity = ifelse(Entity %in% c("North America", "South America", "Central America (BP)"), "America", Entity))
# Calculate the Total Capacity for each merged continent in 1990 and 2021
continents_capacity_merged <- continents_capacity_merged %>%
group_by(Entity, Year) %>%
summarise(TotalCapacity = sum(TotalCapacity))
# Pivot the data to have 1990 and 2021 as columns
continents_capacity_pivot <- continents_capacity_merged %>%
pivot_wider(names_from = Year, values_from = TotalCapacity)
# Calculate the difference in Total Capacity between 2021 and 1990
continents_capacity_pivot <- continents_capacity_pivot %>%
mutate(TotalGrowthCont = `2021` - `1990`)
# Sorting the continents by total growth
continents_capacity_pivot <- continents_capacity_pivot %>%
arrange(desc(TotalGrowthCont))
#head(10)
# Calculate the percentage growth for each continent
continents_capacity_perc <- continents_capacity_pivot %>%
mutate(PercentageGrowthCont = (`2021` / `1990`) * 100)
# Print the continents with the growth in TWh and growth percentage
kable(continents_capacity_perc, format = "markdown", caption = "Growth in Total Electricity Generation and Percentage by Continent from 1990 to 2021.")
In 1990, Asia had 463.04 TWh and in 2021 it had 3657.16 TWh, it is a growth of 3194.12 THw, the highest growth among all the continents, more than twice the growth of America in the second place. Asia is also the continent with the highest percentage growth in that period of time, 789.8%.
In this section, all the results obtained previously are graphed so that it is easier to reach the final conclusions.
# bar chart for the top 10 countries with highest growth in renewable electricity generation from 1990 to 2021
ggplot(top_10_energy, aes(x = reorder(Entity, Total_Growth), y = Total_Growth, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Growth in % of equivalent primary energy 1990-2021",
x = "Country",
y = "Growth (%)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_energy)))
top_10_countries <- c("Denmark", "Iceland", "Germany", "United Kingdom", "Ireland", "Sweden", "Finland", "Ecuador", "Portugal", "Spain")
top_countries_data <- renewable_energy %>%
select("Entity", "Year", "Renewables (% equivalent primary energy)") %>%
filter(Entity %in% top_10_countries, Year >= 1990 & Year <= 2020)
# Plot the historical data for the top 10 countries with a subtitle
ggplot(top_countries_data, aes(x = Year, y = `Renewables (% equivalent primary energy)`, color = Entity, group = Entity)) +
geom_line(linewidth = 1.5) +
labs(title = "Historical Data for the Top 10 Countries 1990-2020",
subtitle = "Renewables % of equivalent primary energy over the years",
x = "Year",
y = "Total Renewables %") +
theme_minimal() +
theme(
plot.title = element_text(size = 20), # Adjust the title font size
plot.subtitle = element_text(size = 14), # Adjust the subtitle font size
axis.title = element_text(size = 16), # Adjust the axis labels font size
legend.position = "bottom" # Move the legend to the bottom of the plot
)
Iceland is the country with the highest % of equivalent primary energy from renewable energies, with almost 80% in 2020 (second graph), but it only grew up 26.5% from 1990 to 2020, while Denmark grew up 36% in the same period of time (first graph). That is why Denmark is the country with the highest growth.
# Create a vector of continent names
continents <- c("Africa", "Asia", "Europe", "North America", "Central America (BP)", "South America", "Oceania", "World")
# Filter the data for years between 1990 and 2021 and for continent names
renewable_energy_continents <- renewable_energy %>%
filter(Year >= 1990 & Year <= 2021, Entity %in% continents)
# Calculate the difference between the last and first year for each continent from 1990 to 2021
renewable_energy_continents <- renewable_energy_continents %>%
group_by(Entity) %>%
summarise(Total_Growth = last(`Renewables (% equivalent primary energy)`) - first(`Renewables (% equivalent primary energy)`))
# Sort continents in descending order based on the difference in renewable energy generation
sorted_continents <- renewable_energy_continents %>%
arrange(desc(Total_Growth))
# bar chart for the top 10 countries with highest growth in renewable electricity generation from 1990 to 2021
ggplot(renewable_energy_continents, aes(x = reorder(Entity, Total_Growth), y = Total_Growth, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Growth by in % of equivalent primary energy by Continents 1990-2021",
x = "Continents",
y = "Growth (%)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(renewable_energy_continents)))
As mentioned in the last section, in this case is not possible to merged North, South and Central America into one single group because the data is in percentage. So, considering that, Europe is the continent with the highest growth percentage with almost 10% from 1990 to 2021. Next, it would be useful to graph the evolution of those countries' growth:
# Create a vector of continent names
continents <- c("Africa", "Asia", "Europe", "North America", "Central America (BP)", "South America", "Oceania", "World")
# Filter the data for years between 1990 and 2021 and for continent names
renewable_energy_continents <- renewable_energy %>%
filter(Year >= 1990 & Year <= 2021, Entity %in% continents)
# Plot the historical data for continents
ggplot(renewable_energy_continents, aes(x = Year, y = `Renewables (% equivalent primary energy)`, color = Entity, group = Entity)) +
geom_line(linewidth = 1.5) +
labs(title = "Historical Data by Continents 1990-2021",
subtitle = "Renewables (% equivalent primary energy) over the years",
x = "Year",
y = "%") +
theme_minimal() +
theme(
plot.title = element_text(size = 21), # Adjust the title font size
plot.subtitle = element_text(size = 14), # Adjust the subtitle font size
axis.title = element_text(size = 16), # Adjust the axis labels font size
legend.position = "bottom" # Move the legend to the bottom of the plot
)
From this graph, South and Central America has the highest % of equivalent primary energy from renewable energies, with around 30%. But that average amount has barely changed since 1990, contrary to Europe, where the % of equivalent primary energy from renewable energies was around 5% in 1990 and it became more than 15% in 30 years.
The world percentage changed from around 7% in 1990 to almost 14% in 2021.
It's important to mention that having the highest growth doesn't mean having the highest % of equivalent primary energy from renewable energies, as shown in the graphs, nor having the highest amount of renewable energy generated, that percentage is only the relation between their fossil and renewable produced energies seen as primary energy.
# Filter the data for years between 1990 and 2021 and for continent names
renewable_energy_world <- renewable_energy %>%
select("Entity", "Year",
Renewables = "Renewables (% equivalent primary energy)",
Wind = "Wind (% equivalent primary energy)",
Hydro = "Hydro (% equivalent primary energy)",
Solar = "Solar (% equivalent primary energy)") %>%
filter(Year >= 1990 & Year <= 2021, Entity == "World" )
# Plot the historical data for continents
ggplot(renewable_energy_world, aes(x = Year, y = `Renewables`, color = Entity, group = Entity)) +
geom_line(linewidth = 1.5) +
labs(title = "World Historical Data 1990-2021",
x = "Year",
y = "% of Total Renewables equivalent primary energy") +
theme_minimal() +
theme(
plot.title = element_text(size = 21), # Adjust the title font size
plot.subtitle = element_text(size = 14), # Adjust the subtitle font size
axis.title = element_text(size = 16), # Adjust the axis labels font size
legend.position = "none" # Move the legend to the bottom of the plot
)
This graph shows the total % of equivalent primary energy from renewable energies in the world from 1990 to 2021. From 1990 to 2007, there was a total grow of less than 2%, after 2007 the situation improved with a continuos growth of more than 5%. Nevertheless, that percentage is still very low, below the 14% in 2021.
The following graph shows data for Hydro, Wind, Solar and other renewable energies:
# Filter the data for years between 1970 and 2021 and for continent names
renewable_energy_world <- renewable_energy %>%
select("Entity", "Year",
Renewables = "Renewables (% equivalent primary energy)",
Wind = "Wind (% equivalent primary energy)",
Hydro = "Hydro (% equivalent primary energy)",
Solar = "Solar (% equivalent primary energy)") %>%
filter(Year >= 1970 & Year <= 2021, Entity == "World" )
# Calculate the 'other' component for each year
renewable_energy_world <- renewable_energy_world %>%
mutate(other = Renewables - Wind - Hydro - Solar)
# Melt the data for plotting
melted_data <- renewable_energy_world %>%
select(Year, Wind, Hydro, Solar, other) %>%
pivot_longer(cols = c(Wind, Hydro, Solar, other), names_to = "Component", values_to = "Value")
# Plot the stacked area chart
ggplot(melted_data, aes(x = Year, y = Value, fill = Component)) +
geom_area() +
labs(title = "Renewable Energy Over Time 1970-2021",
x = "Year",
y = "% of equivalent primary energy",
fill = "") +
scale_fill_manual(values = c( "Wind" = "gray", "Hydro" = "blue", "Solar" = "yellow", "other" = "orange")) +
theme_minimal() +
theme(
plot.title = element_text(size = 21), # Adjust the title font size
plot.subtitle = element_text(size = 14),
axis.title = element_text(size = 16), # Adjust the axis labels font size
legend.position = "bottom" # Move the legend to the bottom of the plot
)
Hydro energy has been the one with the highest share in the world and the most consolidated equivalent primary energy renewable resource, although in the last years, wind, solar and other natural resources has been increasing their shares and almost half of the % of equivalent primary energy comes from them.
In this section, the second dataset in TWh is analyzed.
# Filter the data for the year 2021
countries_electricity_2021 <- countries_ele %>%
filter(Year == 2021)
# Calculate the total renewable electricity generation for each country in 2021
countries_electricity_total <- countries_electricity_2021 %>%
mutate(TotalRenewables = `Electricity from wind (TWh)` + `Electricity from hydro (TWh)` +
`Electricity from solar (TWh)` + `Other renewables including bioenergy (TWh)`) %>%
group_by(Entity) %>%
summarise(TotalGeneration = sum(TotalRenewables, na.rm = TRUE)) %>%
arrange(desc(TotalGeneration)) # Sort in descending order
# Select the top 10 countries
top_10_countries <- countries_electricity_total %>%
top_n(10, TotalGeneration)
# bar chart for the top 10 countries with highest electricity generation by other resources in 2021
ggplot(top_10_countries, aes(x = reorder(Entity, TotalGeneration), y = TotalGeneration, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Electricity Generation by All Resources in 2021",
x = "Country",
y = "Total Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
China is the country with the highest total generation from all renewable resource in 2021.
# bar chart for the top 10 countries with highest electricity generation by wind in 2021
ggplot(top_10_countries_wind, aes(x = reorder(Entity, TotalWind), y = TotalWind, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Electricity Generation by Wind in 2021",
x = "Country",
y = "Total Wind Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
# bar chart for the top 10 countries with highest electricity generation by hydro in 2021
ggplot(top_10_countries_hydro, aes(x = reorder(Entity, TotalHydro), y = TotalHydro, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Electricity Generation by Hydro in 2021",
x = "Country",
y = "Total Hydro Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
# bar chart for the top 10 countries with highest electricity generation by wind in 2021
ggplot(top_10_countries_solar, aes(x = reorder(Entity, TotalSolar), y = TotalSolar, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Electricity Generation by Solar in 2021",
x = "Country",
y = "Total Solar Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
# bar chart for the top 10 countries with highest electricity generation by other resources in 2021
ggplot(top_10_countries_other, aes(x = reorder(Entity, TotalOther), y = TotalOther, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Electricity Generation by Other Resources in 2021",
x = "Country",
y = "Total Other Resources Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
China again is the country with the highest total generation in every category.
# bar chart for the top 10 countries with highest growth in renewable electricity generation from 1990 to 2021
ggplot(top_10_growth, aes(x = reorder(Entity, TotalGrowth), y = TotalGrowth, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Growth in Electricity Generation 1990-2021",
x = "Country",
y = "Total Growth of Renewable Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(top_10_countries)))
China is the country with the highest growth with an increase in it's capacity of more than 2300 TWh from 1990 to 2021, more than four times the total growth of the United States in the second place.
Now, the growth percentage:
# Calculate the percentage growth for each country
top_10_growth <- top_10_growth %>%
mutate(PercentageGrowth = ( `2021`/ `1990`) * 100)
# Plot the bar chart for percentage growth
ggplot(top_10_growth, aes(x = reorder(Entity, PercentageGrowth), y = PercentageGrowth, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Countries with the Highest Growth Percentage in Total Electricity Generation 1990-2021",
x = "Country",
y = "Growth Percentage (%)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1), legend.position = "none")
Speaking of the countries with the highest growt percentage, the United Kingdom leads the way with a growth of more than 2000%, coming from 5.82 TWh in 1990 to 122.2 TWh in 2021.
ggplot(continents_capacity_perc, aes(x = reorder(Entity, TotalGrowthCont), y = TotalGrowthCont, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Growth in Electricity Generation in TWh by Continents 1990-2021",
x = "Continent",
y = "Total Growth of Renewable Generation (TWh)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(continents_capacity_perc)))
# Filter the data for the years 1990 and 2021
continents_capacity_perc <- continents_capacity_perc %>%
filter(!Entity == "World")
# bar chart for the top 10 countries with highest growth in renewable electricity generation from 1990 to 2021
ggplot(continents_capacity_perc, aes(x = reorder(Entity, PercentageGrowthCont), y = PercentageGrowthCont, fill = Entity)) +
geom_bar(stat = "identity") +
labs(title = "Growth in Electricity Generation in % by Continents 1990-2021",
x = "Continent",
y = "Total Growth of Renewable Generation (%)") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
legend.position = "none") +
scale_fill_manual(values = rainbow(nrow(continents_capacity_perc)))
As mentioned in the previous section, in this case it is possible to merge North, South and Central America into one single group, America. So, in this graph it is clear that Asia is the continent with the highest growth in total renewable generation with more than 3000 TWh.
In percentage, Asia is also the continent with the highest growth with almost 800%.
# Filter the data for years between 1970 and 2021 and for continent names
renewable_energy_continents <- continents_ele %>%
select("Entity", "Year",
Wind = "Electricity from wind (TWh)",
Hydro = "Electricity from hydro (TWh)",
Solar = "Electricity from solar (TWh)",
Other = "Other renewables including bioenergy (TWh)") %>%
filter(Year >= 1970 & Year <= 2021, Entity == "World")
# Melt the data for plotting
melted_data_continents <- renewable_energy_continents %>%
pivot_longer(cols = c(Wind, Hydro, Solar, Other), names_to = "Component", values_to = "Value")
# Plot the stacked area chart for continents
ggplot(melted_data_continents, aes(x = Year, y = Value, fill = Component)) +
geom_area() +
labs(title = "World Historical Data 1970-2021",
subtitle = "Electricity Generation from Different Resources",
x = "Year",
y = "Energy (TWh)",
fill = "") +
scale_fill_manual(values = c("Wind" = "gray",
"Hydro" = "blue",
"Solar" = "yellow",
"Other" = "orange")) +
theme_minimal() +
theme(
plot.title = element_text(size = 21),
plot.subtitle = element_text(size = 14),
axis.title = element_text(size = 16),
legend.position = "bottom"
)
This last graph shows the world share of wind, hydro, solar and other renewable resources from 1970 to 2021. Hydro is the renewable resource with the highest share, followed in the last years by wind power generation.
The original dataset can be found in this link.