Using ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community
RStudio
R
Tutorial
Blog
R-tistry
Author
William Okech
Published
December 2, 2023
Introduction
The East African Community is a regional intergovernmental organization comprising eight (8) partner states, namely: Kenya, Tanzania, Uganda, Burundi, Rwanda, South Sudan, Democratic Republic of the Congo, and, most recently, Somalia. Kenya, Tanzania, and Uganda were the founding members in 1967 before the organization dissolved in 1977. The organization was re-established in the year 2000, and new members were accepted in subsequent years: Burundi and Rwanda (2009), South Sudan (2016), Democratic Republic of the Congo (2022), and Somalia (2023).
In this post, I will use ggforce and geom_voronoi_tile() to generate Voronoi diagrams depicting the flags of the East African Community.
This work is inspired by Albert Rapp’s blog post, where he provides examples of the use of ggforce.
Section 2: General equations for generating the voronoi plots
Code
set.seed(23479) # set a random seed for pseudorandom number generatorN <-1000voronoi_1 <-tibble(x =runif(N), y =runif(N)) %>%# create a datasetggplot(aes(x, y)) +geom_voronoi_tile(aes(fill = y)) # generate the voronoi plot
The option in scale_fill_viridis_c() can be set between ‘A’ and ‘H’ and or it can be either “magma”, “inferno”, “plasma”, “viridis”, “cividis”, “rocket”, “mako”, or “turbo.”
The viridis scales provide colour maps that are perceptually uniform in both colour and black-and-white. They are also designed to be perceived by viewers with common forms of colour blindness.
Section 4: Flags of the East African Community and Individual Countries
The goal of this post was to demonstrate that one can use code to generate art. Here, the packages, ggplot2 and ggforce, available in R/RStudio, were used to generate Voronoi diagrams (depicting the flags of East Africa) with geom_voronoi_tile(). To compare the generated diagrams with the original flags look at the Flags of the World page on Worldometer
Assignment
Try and generate your own Voronoi diagram (preferably the flag of your home country or country of residence), save with ggsave() using the correct dimensions and dpi, and the share on social media #aRt