The plot visualises the reigns of monarchs in England from 1066 to 2024, with colour-coded houses. Code explanation is below the code chunk.

install.packages("tidyverse")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
 library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Read data from CSV file
 file_path <- "British_Monarchs.csv"
  monarch_data <- read.csv(file_path)

# Manually specify a set of 10 distinct colours
custom_palette <- c("#1f78b4", "#006633", "#e31a1c", "#ff7f00", "#6a3d9a", "#cc9900", "#000099", "#ff33ff", "#000000", "#663300")

# Create a time series plot with colour-coded houses
ggplot(monarch_data, aes(x = Reign.from, y = Reign.to - Reign.from, label = Monarch, color = House)) +
  geom_segment(aes(xend = Reign.to, yend = Reign.to - Reign.from), linewidth = 2) +
  labs(title = "Monarchs in England (1066-2024)",
       x = "Reign Start Year",
       y = "Reign Length",
       label = "Monarch") +
  theme_bw() +
  geom_text(vjust = -0.5, hjust = -0.1, size = 2.5) +  # Adjust text position for better visibility
  scale_color_manual(values = custom_palette) +  # Use the custom colour palette
  theme(panel.background = element_rect(fill = "#f0f0f0"),  # Set chart background colour
        panel.grid.minor = element_line(color = "#cccccc", linetype = "dashed", linewidth = 0.5),  # Add dashed grid lines
        panel.grid.major = element_line(color = "#cccccc", linetype = "dashed", linewidth = 0.5),  # Add dashed grid lines
        axis.text = element_text(size = 8),  # Adjust axis text size
        axis.title = element_text(size = 10),  # Adjust axis title size
        legend.title = element_blank(),  # Remove legend title
        legend.text = element_text(size = 8))  # Adjust legend text size

A custom colour palette named custom_palette is created with ten distinct colour codes (available colour palettes, did not provide enougth contrast or did not have enougth colours).

The time series plot is created using ggplot2. Key components include:

aes: Aesthetic mappings, specifying the x-axis, y-axis, label, and colour.

geom_segment: Draws line segments representing each monarch’s reign, with the linewidth set to 2.

labs: Sets the plot title and axis labels.

theme_bw(): Applies a black-and-white theme to the plot.

geom_text: Positions text labels for better visibility.

scale_color_manual: Specifies the custom colour palette.

theme: Sets various visual aspects of the plot, such as background colour, grid lines, and text sizes (The element_line() function is used with the linewidth argument to address a deprecation warning).