My First Open Source Contribution!

visualization
r
Author

Dean Hansen

Published

7/14/25

Introduction

I’m (very) proud to announce that I’ve had made my first open source contribution!

You may be interested in what I contributed exactly, and that is what I answer below.

What did I contirbute?

A bit of backstory.

During the 2025 federal election, I became interested in making a few animated plots showing how Canada’s parliament has changed over the years.

I quickly realized that there is no accessible, clean dataset available online to accomplish this goal. So, I decided to spend a few hours data munging on Wikipedia and came up with a list of elections results since 1997.

Now, you may wonder why I only collected data since 1997.

The first reason is that it’s my birth year. The second reason is that federal parties become a bit unwieldy the further back in time you go. So, 1997 seemed like a good place to start my data collection.

Where does the open source part come in?

There is an R package called ggparliament which comes pre-installed with an elections dataset.

Their original dataset had results for a handful of parliaments around the world such as the United States and the Netherlands, but didn’t have anything for Canada.

So, I forked the ggparliament repo, and updated the accompanying elections dataset with Canadian election results between 1997 and 2025.

My PR was officially merged last week, so anyone who downloads the package from GitHub will be able to see my updates.

How can I use the updated dataset?

Let me show you.

Say you’re interested in seeing how federal elections have played out over the past 28 years.

Now that the dataset sits inside ggparliament, with a few clicks we’ll be able to make some pretty neat plots.

Interactive Seat Map

Let’s start off small and make a seat map of the 1997 federal election.

Show Code
## Core set of tidyverse packages used for data cleansing
library('readr')
library('dplyr')
library('tidyr')
library('janitor')
library('stringr')
library('lubridate')
library('forcats')
library('glue')
library('purrr')

## Core set of packages used for data visualization
library('ggplot2')
library('scales')
library('gganimate')

## Add interactivity to the plots
library('ggiraph')

## Now with Canadian Election data
# devtools::install_github(repo = "https://github.com/zmeers/ggparliament")
library('ggparliament')

## ...
canada_federal_election_1997_raw <- 
  election_data |> 
  filter(year == 1997, country == "Canada") |> 
  arrange(desc(seats)) |> 
  select("year", "country", "house", "party_long",
         "party_short", "seats", "government", "colour")

## ...
canada_federal_election_1997 <- 
  parliament_data(
    election_data = canada_federal_election_1997_raw,
    type          = "semicircle", 
    parl_rows     = 8, 
    group         = canada_federal_election_1997_raw$government, 
    party_seats   = canada_federal_election_1997_raw$seats
    )

## ...
plot_1 <- 
  canada_federal_election_1997 |> 
  ggplot(
    aes(x = x, y = y, colour = party_short, data_id = party_long, tooltip = glue("({seats}) {party_long}"))
    ) +
  geom_parliament_seats(size = 5) +
  geom_point_interactive(size = 5) +
  geom_parliament_bar(
    colour = colour, 
    party = party_short,
    label = TRUE
    ) +
  draw_totalseats(
    n = 301, 
    type = "semicircle"
    ) +
  scale_colour_manual(
    values = canada_federal_election_1997$colour, 
    limits = canada_federal_election_1997$party_short
    ) +
  labs(
    title = "Canadian Federal Election Results, 1997",
    subtitle = NULL,
    caption = NULL,
    x = NULL,
    y = NULL,
    colour = NULL
    ) +
  theme_ggparliament(
    legend = FALSE, 
    background_colour = TRUE
    ) +
  theme(
    text = element_text(family = "sans", size = 15),
    plot.title = element_text(face = "bold", margin = margin(t = 0, r = 0, b = 20, l = 0))
    )

## ...
girafe(
  ggobj = plot_1, 
  options = list(
    opts_sizing(rescale = TRUE, width = 1),
    opts_hover(css = "stroke-width: 1.5;"),
    opts_hover_inv(css = "fill: white; stroke: rgba(0, 0, 0, 0.5); stroke-width: 1.5; opacity: 0.9;"),
    opts_tooltip(opacity = 0.80, offx = 20, offy = 20, use_cursor_pos = TRUE, delay_mouseover = 500, delay_mouseout = 500, css = "background-color: black; color: white; font-family: sans-serif; font-size: 13pt; padding-left: 8pt; padding-right: 8pt; padding-top: 5pt; padding-bottom: 5pt")
    )
  )


If you hover over the seats, you can see which party is represented and the total number of seats they won.

One interesting thing about Canada is that the total number of seats (can) increase election to election based on population growth. This is something I might plot out in a future blog post, but I digress. Onto the next chart!

Animation

When one has time available, one must use it.

Below we animate across all elections from 1997 to 2025, using a package called gganimate. I will say, it is notoriously difficult to get a professional looking .gif file using gganimate, but I’ve tried my best.

Conclusion

I had a blast, and I hope you did too.

It’s been my pleasure contributing to ggparliament, and I’m very excited to see what others will do with this data.

Anyways, that’s all for now, happy plotting!