Prime Ministers of the United Kingdom by @ellis2013nz
1 min read

Prime Ministers of the United Kingdom by @ellis2013nz

With the recent announcement of British Prime Minister Keir Starmer’s resignation, many people have been talking about the number of British prime ministers in the last decade, the short tenures of prime ministers, and more. I wanted a historical perspective so I grabbed the data from Wikipedia. Wikipedia offers a single, convenient list of all British prime ministers since the term began to be used informally by Robert Walpole. Walpole was effectively Prime Minister of the Kingdom of Great Britain from 1721.

The first prime minister of United Kingdom of Great Britain and Ireland was William Pitt in 1801; and the United Kingdom of Great Britain and North Ireland was called Andrew Bonar Law in 1922. But these distinctions will be largely ignored for the purposes of this blog post.

Downloading Prime Minister data from Wikipedia

Here is the code to download and import this list from Wikipedia. This worked as of June 23, 2026, but Wikipedia pages are known to change format, so it’s unclear if this will work forever:

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

#-----------------Import and process data------------------------

url <- "

page <- read_html(url)

# The main PM table is the first wikitable on the page
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
  ) |> 
  # drop second line of column titles:
  slice(-1) |> 
  # find the PMs' names - everything up to the first [
  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, "\\[.*?\\]"))) |>  # remove [1] refs
  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()

Longest-serving and longest-serving prime ministers

This allows us to do a simple analysis. First of all, here are the British prime ministers who have served the most, that is, who have had more than one term:

Prime Minister Terms Early start Final finish Total duration
William Ewart Gladstone 4 1868-12-03 1894-03-02 4508
Edward Smith-Stanley 3 1852-02-23 1868-02-25 1381
Robert Gascoyne-Cécil 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 07/13/1765 1782-07-01 478
William Cavendish-Bentinck 2 1783-04-02 1809-10-04 1178
William Pitt the Younger 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 10/12/1834 1846-06-29 1883
Henri-Jean Temple 2 1855-02-06 10/18/1865 3429
Benjamin Disraeli 2 1868-02-27 1880-04-21 2530
Ramsay MacDonald 2 1924-01-22 1935-06-07 2480
Winston Churchill 2 10/05/1940 1955-04-05 3160
Harold Wilson 2 1964-10-16 1976-04-05 2835

Since the mid-20th century, only Churchill and Wilson have had a second chance to be prime minister. In the 19th century it was much more common, with big names like Gladstone, Disraeli and Gascoyne-Cecil dominating politics both inside and outside government.

Here are those who served the longest sentences overall:

Prime Minister Terms Early start Final finish Total duration
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
Robert Gascoyne-Cécil 3 1885-06-23 1902-07-11 5000
William Ewart Gladstone 4 1868-12-03 1894-03-02 4508
Frederic Nord 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
Henri-Jean Temple 2 1855-02-06 10/18/1865 3429

Britain’s first Prime Minister, Robert Walpole, was also the longest-serving Prime Minister. In the 20th and 21st centuries, only Thatcher and Blair make the top ten.

These two simple tables were produced with this code:

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

# prime ministers number of terms and total duration:
pm_summary <- pm_table |> 
  rename(`Prime minister` = pm) |> 
  group_by(`Prime minister`) |> 
  summarise(Terms = length(`Prime minister`),
            `Earliest start` = min(start),
            `Latest finish` = max(end),
            `Total duration` = sum(duration)) |> 
  arrange(desc(Terms), `Earliest start`) 

# Prime ministers with more than one term:
pm_summary |> 
  filter(Terms > 1) |> 
  kable() |> 
  kable_styling() 

# Longest serving prime ministers:
pm_summary |> 
  arrange(desc(`Total duration`)) |> 
  slice(1:10) |> 
  kable() |> 
  kable_styling() 

Graphic summaries

The tables are pretty but the graphs are better. Here is my attempt to summarize all the Prime Ministers of the United Kingdom (and its predecessor, the Kingdom of Great Britain) in one image. You probably need a full size screen for this, but with the right display I think the Gantt chart style works well.

This chart produced with this code. There are some clutter-reducing details here besides my usual blog style, like removing the Y-axis labels and adding them instead as text close to the data. Much easier to read. And by removing the horizontal grid.

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

pm_table |> 
  ggplot(aes(y = pm, yend = pm)) +
  geom_segment(aes(x = start, xend = end),
               linewidth = 2, colour = "steelblue") +
  geom_text(data = distinct(pm_table, pm, last_end),
            aes(label = pm, x = last_end + 500),
            size = 2, hjust = 0, colour = "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 = "Year",
       y = "",
       title = the_title) +
  theme(axis.text.y = element_blank(),
        panel.grid.major.y  = element_blank(),
        panel.border = element_blank(), 
        axis.ticks.y = element_blank())

Secondly, it seems very relevant to draw up a plot of the distribution of durations:

And one showing the trend (or lack of trend) of durations over time:

These two simple plots produced with this code. Perhaps the only particularly interesting point here is how I used a subset of the data to highlight the names of prime ministers whose term lengths are less than 120 days or more than 3,000:

pm_table |> 
  ggplot(aes(x = duration)) +
  geom_density(colour = "steelblue") +
  geom_rug(colour = "steelblue") +
  scale_x_continuous(label = comma) +
  labs(x = "Duration in days",
       title = the_title)

pm_table |> 
  ggplot(aes(x = start, y = duration)) +
  geom_smooth(method = "gam", colour = "white") +
  geom_point(colour = "steelblue") +
  geom_text_repel(data = filter(pm_table, duration < 120 | duration > 3000), 
                   aes(label = pm), size = 2.8, seed = 123) +
  scale_y_sqrt(breaks = c(0.5, 1, 1:4 * 2) * 1000, label = comma) +
  labs(x = "Starting date of premiership",
       y = "Duration in days",
       title = the_title,
      subtitle = "Durations shown are of individual periods in office, not lifetime totals.")

Finally, the big question that seems to be getting a lot of attention. How many prime ministers per decade? Below is my effort to calculate and present this.

We can see that we are indeed going through a decade rich in British Prime Ministers (and which will be even richer in a month or so). But this is not unprecedented. We have experienced similar levels many times in the past, and in the politically turbulent 1830s there were even more premierships.

In fact, in the late 20th century, under Thatcher and Blair, the United Kingdom faced a period of unusually slow turnover of prime ministers. But it was a formative period in the lives of many of today’s political commentators, so it’s no surprise that the current rapid change comes as a surprise.

The code for this is below. Note that I calculated this daily. I’m not 100% sure I got it right, but it passes my simplest reality checks (e.g. manually counting the ones we’ve had in the last ten years – six so far, although we hope to become seven soon).

cumulative_pms <- pm_table |> 
  full_join(tibble(start = seq(from = min(pm_table$start), 
                               to = max(pm_table$end), 
                               by = "1 day"))) |> 
  arrange(start) |> 
  mutate(starting_pms = if_else(is.na(pm), 0 , 1),
         rolling_pms = slide_sum(starting_pms, before = 3653),
         # I'm not sure I've got this right yet, but the idea is that in any given day,
         # the number of PMs in thepast 10 years is however many started in those 10 years,
         # plus 1 PM that you came into the period with. The exception being the time
         # of the very first prime minister, for which time you only have the rolling sum
         # of PMs that started:
         rolling_pms = if_else(start < (pm_table[1, ]$start + 3654), 
                               rolling_pms, 
                               rolling_pms + 1))

# When was the peak number of PMs in the last decade:
arrange(cumulative_pms, desc(rolling_pms))


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

That’s all for now.


PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch