Learning {ggplot2} with generative art

Nicola Rennie

21 June 2022

What is generative art?

“Generative art is art made using a predetermined system that often includes an element of chance.” - Tate (tate.org.uk)

Why is generative art useful?

  • You don’t need to learn {ggplot2} to use {ggplot2}
  • You can’t Google art
  • It’s fun!

Spot the difference!

Spot the difference!

Everything! (except the data…)

Learning {ggplot2} with generative art



Layers of layers

“A layer is a combination of data, stat and geom with a potential position adjustment.”

Layers of layers

“A layer is a combination of data, stat and geom with a potential position adjustment.”

Layers of layers

Layers of layers

Layers of layers



Error: Discrete value supplied to continuous scale

Layers of layers

Instead of layers of geoms, we can construct layers of ggplots using {patchwork}…

Layers of layers

Instead of layers of geoms, we can construct layers of ggplots using {patchwork}…


p1 + inset_element(p2 + 
                     theme(
                       plot.background = element_blank(), 
                       panel.background = element_blank(), 
                       panel.grid = element_blank()), 
                   left = 0, bottom = 0, right = 1, top = 1, 
                   align_to = "full")

Layers of layers

Lesser-spotted geoms

geom_path()

Lesser-spotted geoms

geom_path()

  • Plotting positions or trajectories
  • Arrows in flowcharts

Lesser-spotted geoms

geom_polygon()

Lesser-spotted geoms

geom_polygon()

  • Highlighting points that lie within a critical region
  • Highlighting areas on maps
  • Drawing large arrows / triangles on flowchart diagrams

Lesser-spotted geoms

geom_raster()

Lesser-spotted geoms

geom_raster()

  • Speed
    • geom_point(): 5.5s
    • geom_tile(): 1.3s
    • geom_raster(): 0.6s
  • Alternative to geom_point() for (very) high-dimensional data?

Thank you!