Renewable Energy Production Visualization in R

Last Updated : 23 Jul, 2025

Due to climate change and decreasing fossil fuels, it is important to focus on renewable energy production to maintain the balance. R is a statistical programming language that provides multiple such libraries, making data analysis and visualization easier. Visualizing renewable energy production trends becomes crucial with the increasing urgency to transition to cleaner energy sources. This article explores renewable energy production using a comprehensive dataset and demonstrates how R Programming Language can be employed for insightful visualizations and analysis.

Global Renewable Energy Production Visualization

Renewable energy production is a critical aspect of the global energy landscape. As countries strive to reduce their carbon footprint and transition to cleaner energy sources, visualizing renewable energy production data becomes essential for understanding trends, making informed decisions, and tracking progress.

Dataset Link: Global Renewable Energy Production

1: Install and Load Required Libraries

Firstly we will install the libraries and packages in R that help in data manipulation and visualization. In this article, ggplot2 will play the most important role as it is a powerful library used for graphs and plots.

R
# Install necessary packages

install.packages("ggplot2")
install.packages("dplyr")
install.packages("maps")

# Load Libraries
library(ggplot2)
library(dplyr)
library(maps)

2: Prepare the Data

Ensure your data is in the correct format and aggregate the energy data by country.

R
data<-read.cav(C:\\Users\\GFG19565\\Downloads\\global_renewable_energy_production.csv)

# Check the data
head(data)

Output:

  Year Country SolarEnergy WindEnergy HydroEnergy OtherRenewableEnergy TotalRenewableEnergy
1 2000 USA 437.0861 1435.9286 1544.3897 319.3963 3736.801
2 2001 USA 240.4168 402.7929 398.7421 439.7793 1481.731
3 2002 USA 641.0035 1120.4944 334.9936 486.4594 2582.951
4 2003 USA 849.1984 476.0408 609.1024 132.5320 2066.874
5 2004 USA 373.8180 882.1834 1034.3065 181.0531 2471.361
6 2005 USA 650.6676 381.3420 796.6459 214.8628 2043.518

3. Visualization and Analysis

Now we will visualize the Renewable Energy Production Analysis.

Country-wise Comparison

We can compare the country-wise production of energy to see the highest producer of renewable energy.

R
# Bar plot for country-wise comparison
ggplot(data, aes(x = reorder(Country, -TotalRenewableEnergy),
                 y = TotalRenewableEnergy)) +
  geom_bar(stat = "identity") +
  labs(title = "Country-wise Renewable Energy Production",
       x = "Country", y = "Total Renewable Energy (GWh)") +
  theme_minimal() +
  coord_flip()

Output:

gh
Renewable Energy Production Visualization in R

We can see that France is the highest producer of total renewable energy.

Distribution of Solar Energy Production

Histograms and scatter plots help in understanding the distribution and relationships between different types of renewable energy.

R
# Histogram for Solar Energy
ggplot(data, aes(x = SolarEnergy)) +
  geom_histogram(binwidth = 50, fill = "skyblue", color = "black") +
  labs(title = "Distribution of Solar Energy Production",
       x = "Solar Energy (GWh)", y = "Frequency") +
  theme_minimal()

Output:

energy-distribution-GFG
Distribution of Solar Energy Production

Proportion of Energy country wise

We can create pie charts to show the proportion of each type of renewable energy within a country.

R
# Filter the data for the year 2000
data_2000 <- data %>%
  filter(Year == 2000) %>%
  select(SolarEnergy, WindEnergy, HydroEnergy, OtherRenewableEnergy)

# Convert the data to long format
data_long <- data_2000 %>%
  pivot_longer(cols = everything(), names_to = "EnergyType", values_to = "Energy")

# Create the pie chart
ggplot(data_long, aes(x = "", y = Energy, fill = EnergyType)) +
  geom_bar(width = 1, stat = "identity") +
  coord_polar(theta = "y") +
  theme_minimal() +
  labs(title = "Renewable Energy Production in the USA (2000)",
       x = NULL, y = NULL, fill = "Energy Type") +
  theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        panel.grid = element_blank())

Output:

gh
Renewable Energy Production Visualization in R

This code will produce a pie chart that visualizes the proportion of different types of renewable energy production in the USA for the year 2000.

Contribution of Energy country-wise

Visualize the contribution of each type of renewable energy in total production for each country.

R
# Aggregate by country and energy type
country_long <- data %>%
  group_by(Country) %>%
  summarise(SolarEnergy = sum(SolarEnergy),
            WindEnergy = sum(WindEnergy),
            HydroEnergy = sum(HydroEnergy),
            OtherRenewableEnergy = sum(OtherRenewableEnergy)) %>%
  pivot_longer(cols = -Country, names_to = "EnergyType", values_to = "Energy")

# Plot the stacked bar plot
ggplot(country_long, aes(x = reorder(Country, -Energy), y = Energy, fill = EnergyType)) +
  geom_bar(stat = "identity") +
  labs(title = "Contribution of Each Renewable Energy Type by Country", x = "Country",
       y = "Energy (GWh)") +
  scale_fill_manual(values = c("SolarEnergy" = "lightgreen", "WindEnergy" = "lightblue", 
                               "HydroEnergy" = "cyan", "OtherRenewableEnergy" = "red")) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  theme_minimal()

Output:

energy-countrywise-GFG
Contribution of each renewable energy countrywise

Contribution of different types of energy

Now we will visualize the Contribution of different types of energy.

R
# Pivot longer for box plot
box_data <- data %>%
  pivot_longer(cols = c(SolarEnergy, WindEnergy, HydroEnergy, OtherRenewableEnergy), 
               names_to = "EnergyType", values_to = "Energy")

# Plot the box plot
ggplot(box_data, aes(x = EnergyType, y = Energy, fill = EnergyType)) +
  geom_boxplot() +
  labs(title = "Distribution of Renewable Energy Production by Type", 
       y = "Energy (GWh)") +
  scale_fill_manual(values = c("SolarEnergy" = "yellow", "WindEnergy" = "blue",
                              "HydroEnergy" = "cyan", "OtherRenewableEnergy" = "red")) +
  theme_minimal()

Output:

energy-type-contribution
Renewable Energy Production Visualization in R

Visualize Data on the World Map

Based on the dataset we have we can visualize all kind of energy based on the world map and identify the patterns on global level. First we will analyze the merged data of world.

R
library(maps)

# Get the world map data
world_map <- map_data("world")

# Check the structure of world_map
head(world_map)

# Merge the world map with energy data
energy_data$region <- tolower(energy_data$Country)
world_map$region <- tolower(world_map$region)
world_energy <- merge(world_map, energy_data, by = "region", all.x = TRUE)

# Plot the total renewable energy on the world map
ggplot(world_energy, aes(x = long, y = lat, group = group,fill =TotalRenewableEnergy)) +
  geom_polygon(color = "black") +
  scale_fill_continuous(name = "Total Renewable Energy (GWh)", low = "lightgreen", 
                        high = "darkgreen", na.value = "grey50") +
  labs(title = "Total Renewable Energy Production by Country", x = "", y = "") +
  theme_minimal() +
  theme(axis.text = element_blank(), axis.ticks = element_blank())

Output:

gh
Renewable Energy Production Visualization in R

Conclusion

This article explored different kinds of visualization related to renewable energy production in R programming language. We observed and got various meaningful insights through different graphs which was based on global energy production.

Comment