Drawing a Christmas card with the ggplot2 package



Ken Vu
Cascadia R Conference | June 22, 2024

I. Introduction

Around the time I got my MS in Stats, I was slowly losing my R knowledge

I wanted to spread joy for the Christmas holiday season

Plus, #rtistry examples inspired me to draw using R.

@djnavarro’s flametree

@cutterkom’s generativeart

So what did I decide to do then?

  • BUILD A CHRISTMAS CARD…WITH R CODE!!!

II. The Design Process

a. Visualize the outcome

b. Picking my R packages

Chose the ggplot2 package due to popularity, familiarity, and customization

c. Picking my R packages

  • Additional packages
    • extrafont: for loading in custom fonts
    • dplyr: for wrangling and working with large amounts of data

c. Picking my R packages

library(ggplot2) # for data visualization
library(extrafont) # for loading custom fonts
library(dplyr) # for wrangling data frames

III. The grammar of graphics

a. The grammar of graphics

  • The grammar of graphics is a way of organizing and prepping how data get visualized
  • It usually consists of three major elements
    • The data
    • The aesthetic mapping: arranging where to display your data
    • The geometries: how to display your data (i.e., ggplot2 functions)

b. The layout of the plotting area

ggplot2 displays data on a coordinate system with an x-axis and y-axis

b. The layout of the plotting area

  • Points written in the format (x,y)

b. Sketch’s coordinates meant for ggplot2’s coordinate system

IV. How to plot in ggplot2

Let’s show by drawing bare top part of Christmas tree in this card

STEP 1: Pick a ggplot2 function

  • Ex. geom_point() for scatterplots, geom_polygon() for shapes

STEP 2: Create your data

  • Measurements on sketch translate into points

STEP 3: Start plotting

Drawing out the top part of the tree

TA DA!

III. Conclusion

Three takeaways from this Christmas card project

1. I learned more about how the ggplot2 library works

2. I got better at staying organized with complex projects

3. Be yourself as you KEN do it!

Thank you so much!

Here’s where to connect with me!

@kenvu777

linkedin.com/in/kenvu1

Ken-Vu

Slides

Scan to see all my links: