The plot provides a visual representation of the lengths of monarch
reigns in England over the specified time period. 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)
# Create a time series plot
ggplot(monarch_data, aes(x = Reign.from, y = Reign.to - Reign.from, label = Monarch)) +
geom_segment(aes(xend = Reign.to, yend = Reign.to - Reign.from), linewidth = 2, color = "#000000") +
labs(title = "Monarchs in England (1066-2024)",
x = "Reign Start Year",
y = "Reign Length",
label = "Monarch") +
theme_minimal() +
geom_text(vjust = -.5, hjust = -.1, size = 2.5)

The ggplot function from the ggplot2 package is used to create the
time series plot. The x-axis represents the start year of the reign
(Reign.from), and the y-axis represents the length of the reign
(Reign.to - Reign.from). Each monarch is labeled on the plot.
The geom_segment function is used to draw line segments representing
each monarch’s reign. The labs function is employed to set the plot
title and axis labels. The theme_minimal function is used to apply a
minimalist theme to the plot.
Lastly, the geom_text function is utilised to adjust the position of
text labels for better visibility (vjust and hjust parameters).