It’s All About Perspective

Making A Case for Generative Art

Meghan Harris, MPH

Posit::conf(2023)

September 20th, 2023 | 2023-09-20

A snapchat picture of me showing my baby bump at 37 weeks

A shot of me coding in R Studio while watching a baby monitor

Some artwork I made on maternity leave










Disclaimer

@KazeKomboArt

@KazeKomboArt

@KazeKomboArt

What are we Talking About Today?

  • What is Generative Art?

What are we Talking About Today?

  • What is Generative Art?

  • How Can we Make Generative Art in R or Python?

What are we Talking About Today?

  • What is Generative Art?

  • How Can we Make Generative Art in R or Python?

  • Benefits of Creating Generative Art

What are we Talking About Today?

  • What is Generative Art?

  • How Can we Make Generative Art in R or Python?

  • Benefits of Creating Generative Art

  • What is Data Science?

What are we Talking About Today?

  • What is Generative Art?

  • How Can we Make Generative Art in R or Python?

  • Benefits of Creating Generative Art

  • What is Data Science?

  • Examples of How Generative Art Translates into Data Science

What are we Talking About Today?

  • What is Generative Art?

  • How Can we Make Generative Art in R or Python?

  • Benefits of Creating Generative Art

  • What is Data Science?

  • Examples of How Generative Art Translates into Data Science

  • Final Thoughts










What is Generative Art?

What is Generative Art?



In this room today, Generative Art is defined as:



Artwork created through a program in any language or interface.



As long as a program executes the generation of the art…
…it can be considered generative art.

What is Generative Art?



While all AI Art is generative art…


…All generative art IS NOT AI art


&


While some generative art is randomly calculated by the computer…


…Some generative art is intentional and deliberately calculated by a human










How Can we Make Generative Art
in R or Python?

How Can we Make Generative Art in R or Python?




Making generative art might not be as hard as you think…

You just need ✨data✨ and to

Think outside the grid 📊 of your favorite graphical software/package

How Can we Make Generative Art in R or Python?



Some “Primitive” Graphical Tools🛠



R Packages



If it lets you plot data, it will let you make art…

How Can we Make Generative Art in R or Python?



“I don’t understand how you get the data to put into [ insert your graphical tool of choice here ]”




How Can we Make Generative Art in R or Python?



How Can we Make Generative Art in R or Python?

How Can we Make Generative Art in R or Python?

How Can we Make Generative Art in R or Python?

A Simple Example (In Python)

#====================================================#
# Library Load-in-------------------------------------
from plotnine import *
import pandas as pd

# Image Options---------------------------------------
#Set the color
orange_hex = "#FFBB58"

#Set the width
chonk = 10

# Data Creation----------------------------------------
line = pd.DataFrame({"x" : list(range(0,5)),
                     "y" : 1,
                     "color" : orange_hex,
                     "size" : chonk})

# Plot Creation----------------------------------------
orange_line = (ggplot(line, aes("x", "y"))+
               geom_path(color = line.loc[:,"color"],
                         size = line.loc[:,"size"])+
               coord_equal(ylim = (0,3), xlim = (0,4)))

#View the plot
print(orange_line)



How Can we Make Generative Art in R or Python?

A Simple Example (In Python)

#====================================================#
# Library Load-in-------------------------------------
from plotnine import *
import pandas as pd

# Image Options---------------------------------------
#Set the color
orange_hex = "#FFBB58"

#Set the width
chonk = 10

# Data Creation----------------------------------------
line = pd.DataFrame({"x" : list(range(0,5)),
                     "y" : 1,
                     "color" : orange_hex,
                     "size" : chonk})

# Plot Creation----------------------------------------
orange_line = (ggplot(line, aes("x", "y"))+
               geom_path(color = line.loc[:,"color"],
                         size = line.loc[:,"size"])+
               coord_equal(ylim = (0,3), xlim = (0,4)))

#View the plot
print(orange_line)



How Can we Make Generative Art in R or Python?

A Simple Example (In Python)

#====================================================#
# Library Load-in-------------------------------------
from plotnine import *
import pandas as pd

# Image Options---------------------------------------
#Set the color
orange_hex = "#FFBB58"

#Set the width
chonk = 10

# Data Creation----------------------------------------
line = pd.DataFrame({"x" : list(range(0,5)),
                     "y" : 1,
                     "color" : orange_hex,
                     "size" : chonk})

# Plot Creation----------------------------------------
orange_line = (ggplot(line, aes("x", "y"))+
               geom_path(color = line.loc[:,"color"],
                         size = line.loc[:,"size"])+
               coord_equal(ylim = (0,3), xlim = (0,4)))

#View the plot
print(orange_line)



How Can we Make Generative Art in R or Python?

A Simple Example (In Python)

#====================================================#
# Library Load-in-------------------------------------
from plotnine import *
import pandas as pd

# Image Options---------------------------------------
#Set the color
orange_hex = "#FFBB58"

#Set the width
chonk = 10

# Data Creation----------------------------------------
line = pd.DataFrame({"x" : list(range(0,5)),
                     "y" : 1,
                     "color" : orange_hex,
                     "size" : chonk})

# Plot Creation----------------------------------------
orange_line = (ggplot(line, aes("x", "y"))+
               geom_path(color = line.loc[:,"color"],
                         size = line.loc[:,"size"])+
               coord_equal(ylim = (0,3), xlim = (0,4)))

#View the plot
print(orange_line)



How Can we Make Generative Art in R or Python?

A More Complicated Example (In R)

# Library Load-ins---------------------------------
library(ggplot2); library(dplyr); library(artpack)

# Let's make: a "cityscape" with a sky, moon, and buildings

# Data for the sky---------------------
df_sky <- 
  tibble(x = 0,
         xend = 4,
         y = seq(0,3, length = 100),
         yend = y,
         color = art_pals("sunnyside", 100),
         linewidth = 10
  )

# Plot Creation-----------------------
df_sky |>
  ggplot(aes(x, y, xend = xend, yend = yend)) +
  theme_void() +
  coord_cartesian(expand = FALSE, 
                  xlim = c(0,4),
                  ylim = c(0,3)) +
  geom_segment(color = df_sky$color,
               linewidth = df_sky$linewidth) 


#...



How Can we Make Generative Art in R or Python?

A More Complicated Example (In R)

# Data for the moon----------------------------------------------
df_moon <- tibble(
  x = 2,
  y = 1.5,
  size = 100,
  fill = "#f0e4bb",
  color = "#000000"
)

# Plot Creation--------------------------------------------------
df_sky |>
  ggplot(aes(x,y, xend = xend, yend = yend)) +
  theme_void() +
  coord_cartesian(xlim = c(0,4), ylim = c(0,3),
                  expand = FALSE) +
  geom_segment(color = df_sky$color, 
               linewidth = df_sky$linewidth) +
  geom_point(data = df_moon, aes(x,y),
             color = df_moon$color,
             fill = df_moon$fill,
             size = df_moon$size,
             shape = 21,
             stroke = .5,
             inherit.aes = FALSE)


#...



How Can we Make Generative Art in R or Python?

A More Complicated Example (In R)

# Data for the buildings--------------------------------
df_buildings <- tibble(
  x = 0:4,
  xend = x,
  y = 0,
  yend = sample(seq(.5,2, l = 10), 5, replace = TRUE),
  color = "#000000",linewidth = 60
)

# Plot Creation------------------------------------------
df_sky |>
  ggplot(aes(x,y, xend = xend, yend = yend)) +
  theme_void() +
  coord_cartesian(xlim = c(0,4), ylim = c(0,3),
                  expand = FALSE) +
  geom_segment(color = df_sky$color,
               linewidth = df_sky$linewidth) +
  geom_point(data = df_moon, aes(x,y),
             color = df_moon$color,
             fill = df_moon$fill,
             size = df_moon$size,
             shape = 21,
             stroke = .5,
             inherit.aes = FALSE) +
  geom_segment(data = df_buildings,
               color = df_buildings$color,
               linewidth = df_buildings$linewidth)



How Can we Make Generative Art in R or Python?



The concept of translating data into visuals is the same no matter how simple or complex a piece is…



The hard part is usually the programming or the math🤢







Benefits of Creating
Generative Art

Benefits of Creating Generative Art



People may learn better when they are doing something they enjoy 🤯



If you enjoy creating art…you might learn some things 🤔

Benefits of Creating Generative Art

The Obvious 🎨

  • Improved Data Visualization Skills

Benefits of Creating Generative Art

The Obvious 🎨

  • Improved Data Visualization Skills

Benefits of Creating Generative Art

The Obvious 🎨

  • Improved Data Visualization Skills

Benefits of Creating Generative Art

The Abstract 🧠

  • Mathematical/Logical Reasoning

Benefits of Creating Generative Art

The Abstract 🧠

  • Mathematical/Logical Reasoning

Benefits of Creating Generative Art

The Abstract 🧠

  • Mathematical/Logical Reasoning

Benefits of Creating Generative Art

The Unexpected 😲

  • The Community

Benefits of Creating Generative Art

The Unexpected 😲




  • My first ever package!
  • Data-centric Rtistry Toolkit
  • Early development, but things are coming
  • Now available on CRAN 🎉








What is Data Science?

What is Data Science?


In this room today, Data Science is defined as…

A field that uses statistics, computing, methods, and processes to extract or derive knowledge and insights from data.




We’ll focus on the technical methods and processes (coding) for the remainder of this talk…










Examples of How Generative Art Translates into Data Science

Examples of How Generative Art Translates into Data Science

Iteration♻️


  • Mastering this in Art and Data Science can be a HUGE feat


  • Important concept in both art and Data Science.


  • A lot of scenarios in both fields, where we’d want to do the same thing over and over.

Examples of How Generative Art Translates into Data Science - Iteration♻️


Art Scenario


Task:

  • Want to create a lot of copies of a shape
  • Each shape has a different color, size, and position on the coordinate system
Data Sci Scenario


Task:

  • Want to summarize, label, and save multiple processed data sets all at once


Examples of How Generative Art Translates into Data Science - Iteration♻️

Approach:

  • Isolate the problem….


Art Scenario
Data Sci Scenario

Examples of How Generative Art Translates into Data Science - Iteration♻️

Solution:

  • Use your preferred method of iteration to create a generalized workflow.


Art Scenario


Data Sci Scenario


Examples of How Generative Art Translates into Data Science

Development 📦


  • Learning and honing in on development skills can take you to new levels✨.

  • In Generative Art, this promotes cleaner and robust workflows and more complex operations

  • In Data Science, it does the same, but it’s invaluable

Examples of How Generative Art Translates into Data Science - Development 📦


Art Scenario


Task:

  • Create a function that spits out a color palette based on input choices.


Data Sci Scenario


Task:

  • Want to create a function that left joins a table of existing data to another data frame.

Examples of How Generative Art Translates into Data Science - Development 📦

Approach:

  • Isolate: How do we handle the input?, how is it moving through the function? What is coming out?
Art Scenario


Data Sci Scenario


Examples of How Generative Art Translates into Data Science - Development 📦

Solution:

  • Use your (hopefully) working function and reduce code bloat


Art Scenario


art_pals("pal_2",50)

*Returns 50 calculated colors based on `pal_2`*
Data Sci Scenario


map_ae(df_main, ae_term)

*Returns a joined data frame*
*with data from `df_main` and `df_ae`*

Examples of How Generative Art Translates into Data Science

Communication 💬


  • It’s debatable if you need communication for art

  • In Data Science, you NEED to communicate or else 💀

Examples of How Generative Art Translates into Data Science - Communication 💬

Art Scenario


Task:

  • Need help developing unit test suites for art functions…
Data Sci Scenario


Task:

  • Need to perform a data request for a stakeholder…

Examples of How Generative Art Translates into Data Science - Communication 💬

Approach:

  • Identify what matters…


Art Scenario


“What I am functionally trying to do without the context of the art?”

Data Sci Scenario


“What external context or details about the data am I missing?”


Examples of How Generative Art Translates into Data Science - Communication 💬


Solution:

  • Take the right course of action to get the desired result…


Art Scenario


Create a reprex with the reprex package


# Some function that I can't get to work as expected----
reprex::reprex(
  {
  # UPPERCASES don't work
  is.color("BLUE")
  # lowercases do
  is.color("blue")
  }
)
Data Sci Scenario











Final Thoughts

Final Thoughts



This was a tiny introduction into the concept of one type of generative art


This was personal: Generative Art was MY motivation to learn and do more


Doing something I loved made programming/data science digestible