stack twitter tryhackme rss linkedin cross

Wilco van Esch

Skip to main content

Search results

    Visualising garden colours using R

    Flowering plants (2024)

    As a data visualisation hobby project, I chose to visualise the changing of colours in our back garden.

    This project's header image shows the result to date.

    What I did:

    1. Track the start and end date for the flowering of plants in our back garden
    2. Create a CSV file with columns: Name (Dutch), Name (English), Colour, Font colour, Start date, End date
    3. In Rstudio, write an R script to:
      1. Read the CSV (parsing the dates as dates) using readr
      2. Create a timeline graph using ggplot2 and vistime
    4. Run the R script
    5. Export the graph as an image

    Choices:

    1. Distinguish the white flowers by rendering them on a green background
    2. Ensure enough font contrast by including the font colour in the CSV

    Script:

    library(readr)
    library(ggplot2)
    library(vistime)
    
    blossom <- read_csv("Flowering_Plants_2024.csv",
                        col_types = cols(`Start date` = col_date(format = "%d/%m/%y"),
                                         `End date` = col_date(format = "%d/%m/%y")))
    
    p <- gg_vistime(
      blossom,
      col.event = "Name (English)",
      col.start = "Start date",
      col.end = "End date",
      col.color = "Colour",
      col.fontcolor = "Font colour",
      optimize_y = FALSE,
      linewidth = 10,
      title = "Flowering plants (2024)",
      show_labels = TRUE,
      background_lines = NULL
    )
    
    p + theme(panel.background = element_rect(fill='lightgreen'))