A Red, Red Rose

Return to Data Art Gallery.

R
Interactive
Code
# Packages
library(ggplot2)
library(ggiraph)
library(showtext)

# Fonts
font_add_google("Commissioner")
showtext_auto()
showtext_opts(dpi = 300)

# Parameters
col_palette <- PrettyCols::prettycols("Reds")[1:7]
bg_col <- "grey10"
text_col <- "grey90"
text_family <- "Commissioner"
text_size <- 3.5
s <- 1234

# Processing
poem <- readLines("red_red_rose.txt")
max_n <- max(nchar(poem))
poem <- tolower(poem)
poem <- stringr::str_pad(poem, max_n, side = "right")
poem <- stringr::str_split_fixed(poem, "", n = max_n)
colnames(poem) <- seq_len(max_n)
poem <- tibble::as_tibble(poem)

# Colours
set.seed(s)
unique_chars <- unique(unlist(poem))
unique_chars <- unique_chars[unique_chars %in% letters]
plot_cols <- tibble::tibble(
  value = unique_chars,
  fill_col = sample(
    grDevices::colorRampPalette(col_palette)(length(unique_chars))
  )
)

# Wrangling
plot_data <- poem |>
  dplyr::mutate(y = dplyr::row_number(), .before = 1) |>
  tidyr::pivot_longer(
    cols = -y,
    names_to = "x",
    values_to = "value"
  ) |>
  dplyr::mutate(x = as.numeric(x)) |>
  dplyr::left_join(plot_cols, by = "value") |>
  dplyr::mutate(fill_col = tidyr::replace_na(fill_col, bg_col))

# Plot
g <- ggplot() +
  geom_tile_interactive(
    data = dplyr::filter(plot_data, value != " "),
    mapping = aes(x = x, y = y, fill = fill_col, tooltip = value),
    height = 0.9,
    width = 0.8
  ) +
  geom_text(
    data = dplyr::filter(plot_data, !(value %in% letters)),
    mapping = aes(x = x, y = y, label = value),
    colour = text_col,
    size = text_size,
    family = text_family
  ) +
  scale_y_reverse() +
  scale_fill_identity() +
  theme_void() +
  theme(
    plot.background = element_rect(fill = bg_col, colour = bg_col),
    plot.margin = margin(5, 5, 5, 5)
  )
girafe(ggobj = g)

Robert ‘Rabbie’ Burns was a Scottish poet and lyricist, widely regarded as the national poet of Scotland. Born in 1759, his works often reflected themes of love, nature, and social justice. A Red, Red Rose is a romantic poem comparing the speaker’s deep and enduring love to a freshly bloomed rose and an everlasting melody. He promises unwavering devotion, vowing to love his beloved until the seas run dry and time itself ends.

In this example, each letter of the poem is represented by a different coloured rectangle, with only the punctuation written in font. The red and pink colour palette reflects the colour of the rose in the poem. Though the abstract nature of this representation prevents a viewer from reading the poem itself, it allows them to see patterns in the lengths of lines and words, and repeated phrases more clearly.

Return to Data Art Gallery.