Examine the Evolution of UK Prime Ministers: A Detailed Statistical Overview

Jun 22, 2026 344 views

With the recent resignation of Prime Minister Keir Starmer, discussions around the frequency and term lengths of UK prime ministers have surged. For context, I gathered historical data from Wikipedia, which provides a comprehensive overview since the role became formally recognized with Robert Walpole in the early 18th century.

The first individual to assume the title of prime minister for the United Kingdom of Great Britain and Ireland was William Pitt in 1801, while Andrew Bonar Law marked the beginning for the United Kingdom of Great Britain and Northern Ireland in 1922. For the purpose of this analysis, these distinctions will be set aside.

Retrieving Prime Ministerial Data

To perform a thorough analysis, here's an efficient approach to download and process the data directly from Wikipedia:

library(rvest)
library(tidyverse)
library(janitor)
library(slider) # for rolling sum
library(scales)
library(ggrepel)
library(kableExtra)
#-----------------Data Import and Processing------------------------
url <- "https://en.wikipedia.org/wiki/List_of_prime_ministers_of_the_United_Kingdom"
page <- read_html(url)
pm_table <- page |>
html_element("table.wikitable") |>
html_table(fill = TRUE) |>
clean_names() |>
select(
pm = prime_minister_office_lifespan,
start = term_of_office,
end = term_of_office_2
) |>
slice(-1) |>
mutate(pm = str_extract(pm , ".*?\\["),
pm = str_replace(pm, "\\[", ""),
) |>
mutate(across(everything(), ~ str_remove_all(.x, "\\[.*?\\]"))) |>
mutate(across(everything(), str_squish)) |>
mutate(start = as.Date(start, format = "%d %B %Y"),
end = as.Date(end, format = "%d %B %Y"),
end = if_else(is.na(end) & pm == "Keir Starmer",
as.Date("2026-07-10"),
end),
duration = as.numeric(end - start),) |>
distinct() |>
mutate(pm = fct_reorder(pm, start, .desc = TRUE)) |>
group_by(pm) |>
mutate(last_end = max(end)) |>
ungroup()

Analysis of Prime Ministerial Tenure

The data allows for intriguing insights into the term lengths of UK prime ministers. Here’s a look at the most frequent occupants of the office, particularly those who served multiple terms:

Prime minister Terms Earliest start Latest finish Total duration (days)
William Ewart Gladstone 4 1868-12-03 1894-03-02 4508
Edward Smith-Stanley 3 1852-02-23 1868-02-25 1381
Robert Gascoyne-Cecil 3 1885-06-23 1902-07-11 5000
Stanley Baldwin 3 1923-05-22 1937-05-28 2639
Thomas Pelham-Holles 2 1754-03-16 1762-05-26 2763
Charles Watson-Wentworth 2 1765-07-13 1782-07-01 478
William Pitt the Younger 2 1783-12-19 1806-01-23 6917
Winston Churchill 2 1940-05-10 1955-04-05 3160

Interestingly, since the mid-20th century, the trend of returning officials has noticeably diminished. Prominent names like Gladstone, Disraeli, and Gascoyne-Cecil were well-known for repeatedly returning to power in the 19th century, whereas this is relatively rare in contemporary times.

Next, let’s examine who among them has held office the longest:

Prime minister Terms Earliest start Latest finish Total duration (days)
Robert Walpole 1 1721-04-03 1742-02-11 7619
William Pitt the Younger 2 1783-12-19 1806-01-23 6917
Robert Jenkinson 1 1812-06-08 1827-04-09 5418
Margaret Thatcher 1 1979-05-04 1990-11-28 4226

Notably, Robert Walpole remains the most enduring figure in UK political history, serving as prime minister for over 19 years. Thatcher and Blair make appearances in the top ten lists reflecting more contemporary political climates.

Visualizing Prime Ministerial Trends

While textual data is informative, visual aids enhance comprehension. Below, you can see a Gantt-style chart that summarizes the tenures of UK prime ministers:

This graphical representation is derived from meticulous coding to illustrate duration while minimizing clutter for easier interpretation.

Additionally, I created plots to analyze the duration distribution:

Lastly, examining the number of prime ministers per decade reveals cyclical trends in turnover:

This investigation makes it clear that while the recent turnover of prime ministers might seem historically significant, similar levels of turnover have been recorded in past political upheavals, particularly in the politically charged 1830s.

Ultimately, the analysis brings to light the dynamic nature of political leadership in the UK—a stable yet fluctuating narrative shaped by the country's intricate political history.

Source: free range statistics - R · www.r-bloggers.com

Comments

Sign in to comment.
No comments yet. Be the first to comment.

Related Articles

United Kingdom prime ministers by @ellis2013nz