Project 2 — Data Tidying: Electricity Production by Country
Author
Kevin Villa
Published
October 5, 2026
4. Data Source
This dataset comes from Wikipedia’s “List of countries by electricity production,” which breaks down each country’s electricity generation by source (coal, gas, nuclear, hydro, wind, solar, etc.). This is the same wide format dataset a classmate picked for the Week 5 Discussion 5A post, the generation method is a variable, but it’s spread across separate column headers instead of stored as a value, and some of those headers (like “Other” appearing twice, once for other fossil fuels and once for other renewables) are grouped under informal multi level headers on the source page.
Source: Wikipedia, “List of countries by electricity production,” https://en.wikipedia.org/wiki/List_of_countries_by_electricity_production (data sourced from Ember).
The raw file, preserving the original wide structure with no tidying applied, is committed here:
This table has 24 countries (rows) and 10 columns: a Total_TWh figure plus nine separate generation-source columns (Coal, Gas, Other_Fossil, Nuclear, Hydro, Wind, Solar, Biofuels, Other_Renewable). Generation source is really one variable with multiple possible values, but here it’s spread across nine columns — textbook untidy structure. A number of cells are also blank, representing a country with effectively no reported production from that source (for example, Saudi Arabia has no listed coal generation).
Both business questions from the discussion post were about sustainability: which countries rely most on renewables, and how countries group by their primary energy source. I classify hydro, wind, solar, biofuels, and other_renewable as renewable sources, and coal, gas, and other_fossil as fossil sources (nuclear is counted as neither, since it’s low carbon but not renewable), then calculate each country’s percent of total generation from each group.
top_renewable_countries <- most_renewable$country[1:10]ggplot( country_mix %>%filter(country %in% top_renewable_countries),aes(x =reorder(country, pct), y = pct, fill = category)) +geom_bar(stat ="identity") +coord_flip() +labs(title ="Generation Mix, Top 10 Most Renewable-Reliant Countries",x ="Country", y ="Percent of Total Generation", fill ="Source") +theme_minimal()
Brazil is the most renewable reliant country in the dataset at 86.6% (driven mostly by hydropower), followed by Canada (63.9%) and Germany (59.1%). On the other end, Saudi Arabia generates 97.8% of its electricity from fossil fuels, with Iran close behind at 94.3%, both countries with essentially no hydro potential and large domestic oil and gas supplies to draw on instead.
8. Conclusions
Tidying this table made it possible to compare countries on a fair, common scale (percent of generation, not raw TWh), since a small country like Saudi Arabia and a huge one like China can’t be meaningfully compared on absolute terawatt hours. The renewable share ranges from under 3% (Saudi Arabia) to over 86% (Brazil) across just these 24 countries, which mostly tracks each country’s natural resources , Brazil and Canada both have major rivers to generate hydropower, while Gulf states with large oil and gas reserves lean almost entirely on fossil fuels. A useful next step would be to bring in a population or GDP column so the comparison could move from “percent of generation mix” to “renewable TWh per capita,” which would separate genuinely clean grids from countries that are simply smaller.