Tuesday, June 23, 2026

United Kingdom prime ministers


With the latest resignation announcement from United Kingdom (UK) Prime Minister Keir Starmer, there have been a flurry of individuals speaking about what number of UK prime ministers there have been prior to now decade, quick phrases for prime ministers, and so forth. I wished a historic perspective and so grabbed the info from Wikipedia. Wikipedia has a handy single desk checklist of the entire UK prime ministers for the reason that time period started getting used informally by Robert Walpole. Walpole was successfully prime minister of the Kingdom of Nice Britain from 1721 onwards.

The primary prime minister of the United Kingdom of Nice Britain and Eire was William Pitt in 1801; and of United Kingdom of Nice Britain and Northern Eire was Andrew Bonar Legislation in 1922. However these distinctions might be largely disregarded for the aim of this weblog put up.

Downloading prime ministerial knowledge from Wikipedia

Right here’s code to obtain and import that checklist from Wikipedia. This labored as at 23 June 2026, however Wikipedia pages are recognized to vary in format so it’s brittle about whether or not it can work eternally:

library(rvest)
library(tidyverse)
library(janitor)
library(slider) # for rolling sum
library(scales)
library(ggrepel)
library(kableExtra)

#-----------------Import and course of data------------------------

url <- "https://en.wikipedia.org/wiki/List_of_prime_ministers_of_the_United_Kingdom"

web page <- read_html(url)

# The primary PM desk is the primary wikitable on the web page
pm_table <- web page |>
  html_element("desk.wikitable") |>
  html_table(fill = TRUE) |> 
  clean_names() |> 
  choose(
    pm = prime_minister_office_lifespan,
    begin = term_of_office,
    finish = term_of_office_2
  ) |> 
  # drop second line of column titles:
  slice(-1) |> 
  # discover the PMs' names - every part as much as the primary [
  mutate(pm = str_extract(pm , ".*?["),
         pm = str_replace(pm, "[", ""),
        ) |> 
  # strip all the footnotes and stuff from the dates:
  mutate(across(everything(), ~ str_remove_all(.x, "[.*?]"))) |>  # take away [1] refs
  mutate(throughout(every part(), str_squish)) |> 
  mutate(begin = as.Date(begin, format = "%d %B %Y"),
         finish = as.Date(finish, format = "%d %B %Y"),
         finish = if_else(is.na(finish) & pm == "Keir Starmer",
                       as.Date("2026-07-10"),
                       finish),
        length = as.numeric(finish - begin),) |> 
  distinct() |> 
  mutate(pm = fct_reorder(pm, begin, .desc = TRUE)) |> 
  group_by(pm) |> 
  mutate(last_end = max(finish)) |> 
  ungroup()

Most and longest serving prime ministers

This lets us do some easy evaluation. First, listed here are the UK prime ministers who’ve served essentially the most typically—that’s, had multiple time period:

Prime minister Phrases Earliest begin Newest end Whole length
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 Cavendish-Bentinck 2 1783-04-02 1809-10-04 1178
William Pitt the Youthful 2 1783-12-19 1806-01-23 6917
Arthur Wellesley 2 1828-01-22 1834-12-09 1051
William Lamb 2 1834-07-16 1841-08-30 2447
Robert Peel 2 1834-12-10 1846-06-29 1883
Henry John Temple 2 1855-02-06 1865-10-18 3429
Benjamin Disraeli 2 1868-02-27 1880-04-21 2530
Ramsay MacDonald 2 1924-01-22 1935-06-07 2480
Winston Churchill 2 1940-05-10 1955-04-05 3160
Harold Wilson 2 1964-10-16 1976-04-05 2835

Because the mid twentieth century, solely Churchill and Wilson have had a second probability to be prime minister. Within the nineteenth century it was far more widespread, with huge names like Gladstone, Disraeli and Gascoyne-Cecil dominating politics whereas in authorities and out.

Listed below are those that have served the longest durations in complete:

Prime minister Phrases Earliest begin Newest end Whole length
Robert Walpole 1 1721-04-03 1742-02-11 7619
William Pitt the Youthful 2 1783-12-19 1806-01-23 6917
Robert Jenkinson 1 1812-06-08 1827-04-09 5418
Robert Gascoyne-Cecil 3 1885-06-23 1902-07-11 5000
William Ewart Gladstone 4 1868-12-03 1894-03-02 4508
Frederick North 1 1770-01-28 1782-03-27 4441
Margaret Thatcher 1 1979-05-04 1990-11-28 4226
Henry Pelham 1 1743-08-27 1754-03-06 3844
Tony Blair 1 1997-05-02 2007-06-27 3708
Henry John Temple 2 1855-02-06 1865-10-18 3429

The primary UK prime minister, Robert Walpole, was additionally the longest serving. From the twentieth and twenty first century, solely Thatcher and Blair make the highest ten checklist.

These two easy tables have been produced with this code:

#------------summary highlights----------

# prime ministers variety of phrases and complete length:
pm_summary <- pm_table |> 
  rename(`Prime minister` = pm) |> 
  group_by(`Prime minister`) |> 
  summarise(Phrases = size(`Prime minister`),
            `Earliest begin` = min(begin),
            `Newest end` = max(finish),
            `Whole length` = sum(length)) |> 
  organize(desc(Phrases), `Earliest begin`) 

# Prime ministers with multiple time period:
pm_summary |> 
  filter(Phrases > 1) |> 
  kable() |> 
  kable_styling() 

# Longest serving prime ministers:
pm_summary |> 
  organize(desc(`Whole length`)) |> 
  slice(1:10) |> 
  kable() |> 
  kable_styling() 

Graphic summaries

Tables are good however graphics are higher. Right here is my try to summarise all of the prime ministers of the UK (and of the predecessor Kingdom of Nice Britain) in a single image. You in all probability want a full-sized display screen for this, however with the suitable show I believe the Gantt chartish fashion works properly.

That chart produced with this code. There are a number of clutter-minimisation sprucing particulars right here on prime of my typical weblog fashion, like suppressing the y axis labels and including them as a substitute as textual content near the info. A lot simpler to learn. And suppressing the horizontal gridlines.

--------------Draw plots-------------
the_title <- "Prime ministers of the UK and its predecessors, 1721 to 2026"

pm_table |> 
  ggplot(aes(y = pm, yend = pm)) +
  geom_segment(aes(x = begin, xend = finish),
               linewidth = 2, color = "steelblue") +
  geom_text(knowledge = distinct(pm_table, pm, last_end),
            aes(label = pm, x = last_end + 500),
            measurement = 2, hjust = 0, color = "grey50") +
  scale_x_date(
    breaks = seq(as.Date("1720-01-01"), as.Date("2035-01-01"), by = "20 years"),
    date_labels = "%Y",
    sec.axis = sec_axis(~.),
  ) + 
  labs(x = "Yr",
       y = "",
       title = the_title) +
  theme(axis.textual content.y = element_blank(),
        panel.grid.main.y  = element_blank(),
        panel.border = element_blank(), 
        axis.ticks.y = element_blank())

Secondly, it appears extremely related to supply a plot of the distribution of durations:

And one displaying the development (or lack of development) in durations over time:

These two easy plots produced with this code. Maybe the one level of explicit curiosity right here is how I used a subset of the info to spotlight the names of prime ministers with time period length of lower than 120 days or greater than 3,000:

pm_table |> 
  ggplot(aes(x = length)) +
  geom_density(color = "steelblue") +
  geom_rug(color = "steelblue") +
  scale_x_continuous(label = comma) +
  labs(x = "Length in days",
       title = the_title)

pm_table |> 
  ggplot(aes(x = begin, y = length)) +
  geom_smooth(methodology = "gam", color = "white") +
  geom_point(color = "steelblue") +
  geom_text_repel(knowledge = filter(pm_table, length < 120 | length > 3000), 
                   aes(label = pm), measurement = 2.8, seed = 123) +
  scale_y_sqrt(breaks = c(0.5, 1, 1:4 * 2) * 1000, label = comma) +
  labs(x = "Beginning date of premiership",
       y = "Length in days",
       title = the_title,
      subtitle = "Durations proven are of particular person durations in workplace, not lifetime totals.")

Lastly, the large query that appears to get a whole lot of consideration. What number of prime ministers per decade? Under is my effort at calculating and presenting this.

We are able to see that we’re certainly going by a decade that’s wealthy in UK prime ministers (and might be richer nonetheless in a month or so). But it surely’s not unprecedented. We’ve been at related ranges seeral instances prior to now, and within the politically turbulent 1830s there have been much more premierships.

In truth, within the late twentieth century with Thatcher and Blair, the UK confronted a interval of unusually gradual turnover of prime ministers. However that was a formative interval within the lifetime of a lot of right now’s political commentators, so its not stunning that the present fast turnover comes throughout as a shock.

Code for that is under. Observe that I calculated this each day. I’m not 100% I’ve bought it proper, but it surely passes my easiest actuality checks (eg manually counting these we’ve had prior to now ten years – six to date, though expeted quickly to grow to be seven).

cumulative_pms <- pm_table |> 
  full_join(tibble(begin = seq(from = min(pm_table$begin), 
                               to = max(pm_table$finish), 
                               by = "1 day"))) |> 
  organize(begin) |> 
  mutate(starting_pms = if_else(is.na(pm), 0 , 1),
         rolling_pms = slide_sum(starting_pms, earlier than = 3653),
         # I am undecided I've bought this proper but, however the concept is that in any given day,
         # the variety of PMs in thepast 10 years is nonetheless many began in these 10 years,
         # plus 1 PM that you simply got here into the interval with. The exception being the time
         # of the very first prime minister, for which era you solely have the rolling sum
         # of PMs that began:
         rolling_pms = if_else(begin < (pm_table[1, ]$begin + 3654), 
                               rolling_pms, 
                               rolling_pms + 1))

# When was the height variety of PMs within the final decade:
organize(cumulative_pms, desc(rolling_pms))


cumulative_pms |> 
  ggplot(aes(x = begin, y = rolling_pms)) +
  geom_line(color = "steelblue") +
  scale_y_continuous(breaks = 0:max(cumulative_pms$rolling_pms)) +
  labs(x = "",
       y = "Variety of prime ministers in previous 10 years",
       title = the_title,
       subtitle = "Peak prime ministers per decade was within the 1830s")

That’s all for now.



Related Articles

Latest Articles