Nigeria runs the largest democracy on the African continent. With over 93 million registered voters as of 2023, its electoral cycles are not just political events but economic, sociological, and institutional stress tests. Yet for all the scale of Nigerian elections, the data that explains how people actually vote has historically lived in scattered PDFs, delayed government portals, and academic papers with restricted access. This project sets out to change that.
The Nigeria Election Analytics Dashboard is a fully interactive, eight-page Streamlit application that consolidates twelve years of electoral data into a single environment where researchers, journalists, policy analysts, and civic technologists can explore presidential results, party vote share trends, regional voting patterns, voter turnout dynamics, National Assembly compositions, governorship outcomes, and statistical anomaly signals all in one place.
This writeup walks through every decision made in building the dashboard: how the data was sourced and structured, why certain visualisation types were chosen over others, how the application is architecturally organised, and what the numbers themselves reveal about Nigeria's democratic evolution between 2011 and 2023.
Data Sources and Collection
Every good analytics project is only as credible as the data underneath it. For this dashboard, data was drawn from four primary institutional sources, each covering a different layer of the electoral record.
Primary Sources
The Independent National Electoral Commission (INEC) is the constitutional body responsible for conducting elections in Nigeria. Their official results portal at inec.gov.ng and the IReV (INEC Result Viewing) portal introduced in 2023 were the foundation for all state-level presidential, gubernatorial, and legislative results. INEC publishes collated results in official gazettes and press releases following each election cycle, and the 2023 results were the first to be transmitted digitally from polling units via the BVAS device system.
The International Foundation for Electoral Systems (IFES) Election Guide maintains a comprehensive database of registered voter statistics, turnout figures, and election administration data across all democracies. Their records provided the longitudinal voter registration data stretching from 2011 through 2023, including the official turnout percentages used throughout the dashboard.
The Inter-Parliamentary Union (IPU) Parline database is the global standard for parliamentary election data. All National Assembly seat compositions, both Senate and House of Representatives, were cross-referenced against IPU Parline records for accuracy. Their data covers the final seat counts after tribunal rulings and by-election adjustments.
Dataphyte, a Nigerian data journalism organisation, operates an elections portal at elections.dataphyte.com that provides cleaned, machine-readable state and LGA-level data. Their work was instrumental in validating state-level presidential results for 2015 and 2019 where INEC's own portal had formatting inconsistencies.
Data Structure
Rather than storing raw CSV files that would require runtime parsing, all data was structured into Python dictionaries within a dedicated data/nigeria_election_data.py module. This approach keeps the application dependency-light, makes the data instantly inspectable by any Python developer, and removes the risk of file-path failures in deployment environments. Helper functions then convert these dictionaries into pandas DataFrames on demand.
# State-level presidential results — 2023
# Source: INEC Official Collated Results
STATE_PRESIDENTIAL_2023 = {
"Lagos": {"APC": 572_606, "PDP": 75_750, "LP": 582_454, "NNPP": 14_000},
"Kano": {"APC": 401_000, "PDP": 277_000, "LP": 35_000, "NNPP": 994_627},
"Rivers": {"APC": 230_000, "PDP": 240_000, "LP": 175_000, "NNPP": 7_000},
# ... 34 more states
}
def get_state_results(year=2023):
mapping = {2023: STATE_PRESIDENTIAL_2023, ...}
df = pd.DataFrame(mapping[year])
df["Winner_Party"] = df[parties].idxmax(axis=1)
return df
The full dataset covers 37 administrative units (36 states plus the FCT), four election cycles from 2011 to 2023, four major parties (APC, PDP, LP, NNPP) plus historical parties (CPC, ACN, ANPP), all six geopolitical zones with state-to-zone mappings, and 37 gubernatorial results for the 2023 cycle.
Turnout dropped 26.6 percentage points over 12 years despite 20 million new registered voters joining the roll.
Application Architecture
The dashboard follows a clean separation-of-concerns pattern with three distinct layers: a data layer that holds all raw and computed figures, a utilities layer that provides reusable chart-building functions, and a pages layer that contains each screen as an independently importable module.
Streamlit's session-based routing is handled through a radio button widget in the sidebar that maps user selections to page module imports. Each page file exports a single show() function, making it trivial to add new pages or test them independently. The sidebar navigation and global CSS stylesheet live in app.py, giving every page a consistent dark theme without any repetition.
Chart Utilities Design
All eight pages share the same chart-building functions from utils/charts.py. The module defines a DARK_TEMPLATE dictionary that holds Plotly's paper background, plot background, font family, grid line colours, and legend styling, which is applied to every figure through a single apply_dark(fig, title, height) call. This means changing the dashboard's visual theme requires editing exactly one dictionary rather than touching dozens of individual chart configurations.
Party colours are stored as a dictionary constant rather than hardcoded strings, so any chart that receives party names as labels automatically renders APC in green, PDP in red, Labour Party in amber, and NNPP in blue, with a fallback grey for lesser parties. This consistency is particularly important in the cross-page comparisons where users switch between the presidential results view and the regional analysis and need colour continuity to track the same party across different chart types.
Dashboard Pages and Visualisations
The dashboard is organised into eight pages, each addressing a distinct analytical question. The design principle throughout was to start every page with a summary metric row that gives users their bearings before diving into more complex charts below.
-
Overview and KPIs A landing page with five headline metrics, a dual-axis bar and line chart combining GDP-style nominal size with real growth rate, a 2024 sector donut, a per capita versus inflation dual-axis chart with annotated shock lines, and a visual event timeline showing all eleven election-cycle winners with their vote totals and turnout rates.
-
Presidential Results Year selector driving a national donut chart and results table. For 2015, 2019, and 2023, a horizontal stacked bar chart shows the top fifteen states by votes cast broken down by party. Below the chart, a grid of party-win-count badges summarises how many states each party carried, followed by a full 37-state expandable data table.
-
Vote Share and Trends A multi-line chart tracing presidential vote share percentages from 2011 to 2023 for APC, PDP, LP, and NNPP. Beneath it, a grouped bar chart shows absolute vote counts side by side. Two waterfall charts then isolate the cycle-over-cycle change for APC and PDP individually, making the scale of APC's vote erosion between 2015 and 2023 immediately legible.
-
Regional and Geopolitical Analysis A grouped bar chart compares party totals across the six geopolitical zones. Dominant-party cards for each zone display share percentages. A Plotly treemap lets users see how the entire national vote mass is distributed by zone and state simultaneously, with colour encoding showing the winning party in each territory.
-
Voter Turnout Four gauge charts, one per election cycle, show the headline turnout figure with colour-coding shifting from green in 2011 to red in 2023. A shaded area chart overlays registered voter growth against declining votes cast to visualise the widening participation gap. A horizontal bar chart ranks all 37 states by 2023 accreditation rate, with bars coloured by geopolitical zone.
-
National Assembly Senate and House of Representatives seat compositions presented as donut charts alongside horizontal bar charts with a dashed majority-threshold line. Below these, trend lines trace how Senate and House seat counts for each party changed across all four elections, clearly showing when APC superseded PDP as the dominant legislative force in 2015.
-
Governorship Results A full horizontal bar chart showing all 36 state winners with their vote totals, coloured by party. A treemap breaks this down by geopolitical zone. A complete data table below lists governor, party, state, zone, and winning vote total for every state, sortable and filterable via Streamlit's built-in dataframe controls.
-
Anomaly Detector Four tabs cover Benford's Law analysis, turnout outlier detection using z-scores, win margin spike detection via scatter plot, and a curated summary of documented irregularities. The Benford analysis computes a chi-square deviation score to flag whether the first-digit distribution of state-level vote totals conforms to natural occurrence patterns.
Key Analytical Findings
Beyond the engineering decisions, the data itself tells a compelling story about how Nigerian democracy has changed over twelve years. Several findings emerged that were counterintuitive or underreported in mainstream coverage of the elections.
The Vote Collapse of 2023
The single most striking number in the dataset is not who won in 2023 but how few votes it took to win. Bola Tinubu was declared president with 8.79 million votes. In 2015, Muhammadu Buhari won with 15.4 million votes against a more fragmented field. In absolute terms, the 2023 winning total is lower than the losing total of every previous election since 2011. Registration grew by over 20 million between 2015 and 2023, yet votes cast fell from 29.4 million to 25.3 million. This simultaneous expansion of the voter roll and contraction of actual participation is the defining paradox of the 2023 election.
The dashboard's turnout page makes this visible through a gap chart that stacks votes cast against did-not-vote figures per cycle. By 2023 the did-not-vote bar dwarfs the votes-cast bar, an image that no text-based report quite captures with the same immediacy.
Labour Party and the Third-Party Moment
Peter Obi's Labour Party candidacy in 2023 produced the strongest third-party performance since Nigeria's return to multiparty democracy in 1999. The party received 6.1 million votes nationally, roughly 24 percent of the total, and swept the entire South East geopolitical zone for the first time any party other than PDP had done so. The regional analysis page shows this vividly: the South East treemap squares are uniformly amber, a colour that had appeared nowhere on that map in any previous election cycle.
APC's Legislative Hold Despite Executive Erosion
There is a striking divergence between APC's presidential vote performance and its legislative dominance. Tinubu won with just 34.8 percent of the presidential vote, a figure that would have been insufficient to win in 2015 or 2019. Yet APC retained 59 Senate seats and 178 House seats in the same 2023 election. This split between presidential fragmentation and legislative consolidation suggests that candidate-level factors rather than pure party affiliation drove the 2023 presidential result, a distinction the National Assembly page makes clear through its seat trend lines.
The Anomaly of the North West
The North West zone, comprising seven states including Kano, Katsina, and Sokoto, has been the decisive electoral zone in every election since 2015. Its massive registered voter base, high turnout relative to the south, and historically block-voting patterns make it a structural advantage for whichever party dominates it. In 2023, however, NNPP's Kano result (994,627 votes for the gubernatorial candidate alone) introduced competitive fragmentation that the anomaly detector flags through its z-score turnout analysis as statistically atypical at the state level.
Presidential Results Summary
| Year | Winner | Party | Winner Votes | Turnout | Registered |
|---|---|---|---|---|---|
| 2011 | Goodluck Jonathan | PDP | 22,495,187 | 53.7% | 73.5M |
| 2015 | Muhammadu Buhari | APC | 15,424,921 | 43.7% | 67.4M |
| 2019 | Muhammadu Buhari | APC | 15,191,847 | 34.8% | 82.3M |
| 2023 | Bola Tinubu | APC | 8,794,726 | 27.1% | 93.5M |
Sources: INEC Official Collated Results; IFES Election Guide voter registration and turnout figures.
Tools and Technology
References and Data Citations
- INEC (2023). 2023 General Election Official Results. Independent National Electoral Commission of Nigeria. www.inec.gov.ng
- INEC IReV Portal (2023). Presidential Election Result Viewing Portal. INEC. irev.inec.gov.ng
- IFES Election Guide. Nigeria Election Archive: Voter Registration and Turnout 2011 to 2023. International Foundation for Electoral Systems. www.electionguide.org
- IPU Parline (2023). Nigeria: National Assembly Elections 2011, 2015, 2019, 2023. Inter-Parliamentary Union. data.ipu.org
- Dataphyte Elections Portal. Nigeria Election Data Hub: State-Level Results and Candidate Data. Dataphyte. elections.dataphyte.com
- YIAGA Africa (2023). Watching the Vote: 2023 General Elections Report. YIAGA Africa ERAD Platform. erad.ng
- EU Election Observation Mission Nigeria (2023). Final Report: Presidential and National Assembly Elections, 25 February 2023. European External Action Service. www.eeas.europa.eu
- NBS (2023). Nigeria State Zone Classification and Administrative Boundaries. National Bureau of Statistics. www.nigerianstat.gov.ng
- Benford, F. (1938). The Law of Anomalous Numbers. Proceedings of the American Philosophical Society, 78(4), 551 to 572. Used as the theoretical basis for the anomaly detection chi-square analysis.
- Streamlit Inc. (2024). Streamlit Documentation. docs.streamlit.io
- Plotly Technologies Inc. (2024). Plotly Python Graphing Library. plotly.com/python