Resources

It's All About Perspective: Making a Case for Generative Art - posit::conf(2023)

Presented by Meghan Santiago Harris This talk explores how to create art in the R language while highlighting some similarities between the skills required for creating generative art and those needed to perform data science tasks in R. Because the field of data science is inherently task-oriented, it is no wonder that most people struggle to see the utility of generative art past the bounds of a casual hobby. This talk will invite the participant to learn about generative art while focusing on ""why"" people should create it and its potential place in data science. This talk is suitable for all disciplines and artistic abilities. Furthermore, this talk will aim to expand the participant's perspective on generative art with the following concepts: - What is generative art and how can it be created in R or Python - Justifications for generative art within Data Science - Examples of programming skills that are transferrable between generative art and pragmatic data science projects Materials: - Link to the talk repo: https://github.com/Meghansaha/a_case_for_genart - Link to the slides: https://meghansaha.github.io/a_case_for_genart/#/title-slide - Link to the artpack package site: https://meghansaha.github.io/artpack/ - Personal Site: https://thetidytrekker.com/ Presented at Posit Conference, between Sept 19-20 2023, Learn more at posit.co/conference. -------------------------- Talk Track: Developing your skillset; building your career. Session Code: TALK-1109

image: thumbnail.jpg

Transcript#

This transcript was generated automatically and may contain errors.

Hello, I'm Megan Harris. I'm a data scientist at the Prostate Cancer Clinical Trials Consortium, and I'm also a generative artist that's here to introduce you all to generative art and a different approach to learning data science. But before I do that, I have to say, I feel like I'm only standing here because I decided to stop working 10 months ago. Now, I didn't quit my job or anything, but as you can see here, I was very pregnant and ready to pop.

I gave birth to a beautiful baby. I went on maternity leave for six months. I actually found time to code on leave. But I had a rule for myself to only code if it was for fun stuff like art. So by the end of my leave, I was amazed at how coding art like this helped with the practical data science skills I needed when I returned to work. And I'm going to give a tiny glimpse into how that was possible.

So quick disclaimer, it's okay if you don't know how to make generative art. It's okay if you don't even like art. And it's totally okay if you don't know much about data science. My hope is that you treat this talk like a choose-your-own-adventure. You know, just like those old Goosebump books. Hopefully, I'm not the only old person in here who remembers those, right? They kind of looked like this. So whether you're here for the art, or the data science, or just learning, I'm hoping that there will be something for you to take away from this today. And aren't those pictures awesome? My husband drew those characters for me. I love them.

What is generative art?

Okay. So quick rundown. Obviously, we're going to talk about what is generative art. I'll go into how we can make it in R or Python. I'll go into some benefits of creating art. Then we'll switch gears and quickly talk about what data science is. I'll give some examples of how generative art translates into data science. And I'll leave you all with some final thoughts.

Okay. So I want to pose a question to you all. You don't have to answer me out loud. But just think for a second. What do you think generative art is? Is it opening up a digital sketch pad and physically drawing on a screen? Or creating outputs with AI art platforms like Dolly or Lenza? I couldn't find an official definition for you all that I liked. So I'm making one right here right now, because I can. So 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 a generation of the art, it can be considered generative art.

Now, this is vague in general. And yes, that's on purpose. Because I can guarantee you that there are multiple definitions of generative art floating around in this room right now. I'm also going to assume that at least one of you in here is thinking of AI art. We are not talking about AI art today. And I do have two statements regarding that. So while all AI art is generative art, all generative art is not AI art. And while some generative art is randomly calculated by the computer, some generative art is intentional and deliberately calculated by a human.

Making art in R or Python

So it's safe to say we probably have some data people in here. And that some of you have probably created visualizations with R or Python. So if you know how to make visuals in this manner, you are already so close to making generative art. It really might not be as hard as you think. You just need the data and the ability to think outside the grid, if you will, of your favorite graphical software or package.

Now, I'm going to be real with y'all for a second. I don't have enough time here to truly explain in depth how to make complicated art with code. I mean, Posit, Jenny, Hadley, I got my email. I can help with the workshop next year if y'all want. I'm just saying. I'm willing. But for right now, all of the code examples for the art you'll see today is on this talk's GitHub repo. So you can all listen to me attempt to give a crash course right now. But after the dust has settled and you're back home, know that these resources are available to you later.

Okay. So when first trying to create art in R or Python, it's helpful to pick a data visualization tool you're comfortable with. For me, that's ggplot2 at R, but you can use whatever language and tool you'd like. The main point is that if a tool lets you plot data, it will let you make art. The challenge comes in when you need to understand the translation of the data into visuals.

So without fail, whenever I do a talk like this, there's always somebody who says, I don't understand how you get the data to put into insert your graphical tool of choice here. And I get it. It can be tricky. So let's stop for a minute and imagine that we want to draw a line on a piece of paper, like in the real world. So if someone is able to pick up a pen and use it, we might assume it's easy for them to draw a single line on a paper. But we can argue that it might be hard to make a straight line, right? So let's say we upgrade to a graph paper instead. Now this may be way easier because we have that visual guide of the gridlines, but if you stop and think, where have we probably seen a grid like this before? Possibly in your favorite visualization tools. For me, it's ggplot2. The gridlines reminds me of the coordinate system all ggplots are created on. So knowing this, we can set values to every mark we make on the paper, just like the coordinate system in your favorite tool would. We have four coordinate points in this line, each with an x and y value, where we have four values from 1 to 4 on the x axis, and a constant value of 1 repeated four times on the y axis to make this straight line.

Now this may seem overly simple, but that's it. That's all it takes to create generative art. The trick here is that you need to understand the relationship between the visuals you want, the data you need, and the coordinate system you set.

The trick here is that you need to understand the relationship between the visuals you want, the data you need, and the coordinate system you set.

So now let's look at this example in more detail in Python. So there can be different approaches to our last example, but here's just one way. Now don't get too bogged down in the specifics of the code. We just want to focus on the process happening here. So first we'll load in those libraries. Here is Plot9 for plotting and pandas for data frame creation. Then we can do some prep for our data. Here we're just storing values and objects for the color and size of our line. Next, the most important step is creating the data frame. Here is a pandas data frame with x and y coordinates and values for the color and size of the line. Finally, we can feed this data frame into the set of ggplot functions at the bottom there to create the plot. And after we print it, we get the image on the right.

Now this was a simple example, so let's step it up a bit in something I'm comfortable with, which is R. So again, we're not focusing on the code per se, but we just want to observe the general relationship going on between the data and the visual. So again, we start with the packages. Here we have ggplot2 for plotting, dplyr for data frame creation, and artpack, which I'll talk about in the next section. And we need an idea. So let's say we'll make a simple cityscape with a sky, a moon, and some buildings. So because we want a sky in our background, we can make the data for that first. So we make a data frame with numbers that when mapped on the ggplot will look like horizontal lines filling the page. We also can add in variables for the color and size of the lines. And when this data frame is plotted with the geom segment function there at the bottom, we get this beautiful gradient on the right. Next, let's say we want to have a big, simple moon. So again, we make another data frame that only has data for one single point. It has a big numeric value for size and some color options. We then add this data frame into the plot with the geom point function at the bottom, and that creates the image on the right. Finally, we make one last data frame for some basic buildings. This time the data frame will have numbers that will plot chunky vertical lines. We can also go a little spicy and throw in a sample function to randomize the heights of our buildings. And like all the other layers, we tack it on with a geom segment function at the bottom, and we get the image on the right.

Now, I know that was really quick, but the main thing I want you to take away from that is that 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. And if you hate math like I do, don't worry. It's okay. You can still make art. I'm proof. But I also hope you all took note of how intentional a lot of the process can be. While there's some artists out there that rely heavily on completely automated systems or fine-tuning AI prompts, there are some of us out here spending hours exploring and creating art with code in this manner.

Benefits of creating generative art

So now that we all know vaguely how we can make this in R or Python, let's get into some benefits. Now, I'm biased. I think there's lots of benefits to making art like this. But the most important for me is just how fun and therapeutic it can be. Another big one is just learning, though, in general. And it got me to thinking about something. So I have this idea that people may learn better when they're doing something they enjoy. And if you enjoy creating art, you might learn some things. Now, I'm not trying to be funny, but I can't just stand up here and say that this is a proven fact, right? So the best I can do is give you personal examples of how I've benefited from making art.

So one of the most obvious is that of improved data visualization skills. And I love to use this example. So what you're all looking at is my very first Tidy Tuesday submission I did years ago. So for any of you who don't know, Tidy Tuesday is a weekly data challenge that we have in the R for DS community. It used to be super popular on Twitter before it became a health site. But this was my first submission, and you couldn't tell me nothing. I was so happy to make that lollipop chart, as I should have been. But this was my work only two months after creating Genitive Art, and this was my most recent Tidy Tuesday I did this year. So thank you. Obviously, I developed knowledge of how to make things more aesthetically pleasing and how to hack my tool of choice for some cool results.

So there are some more abstract benefits as well, like mathematical and logical reasoning. Like, imagine how pissed I was when I found out math was involved to make art, man. It sucks. But the truth is that art can require you to know about patterns, numeric sequences, and just general logic. And logic like that is what makes it possible to go from a grid of points like this to a grid with skipped patterns like this to a finished piece of art like this without having to manually create the data for every single pixel shown here.

So there are also some unexpected benefits as well. So one of that being the community. Making Genitive Art gave me another reason to interact with people and just share what I was doing. And funny enough, in this tweet, I'm not calling it whatever it is, it's a tweet. When I made this tweet last year, I was talking with others about how I wanted to create an art package. But I was admitting that I was afraid to because I didn't have a formal developer background and I didn't feel smart enough, which is now hilarious to me, because another unexpected benefit was that of package development. So, yes, I made my first ever package called the Art Pack. Thank you. It's an artistry toolkit that's in early development, but as of three weeks ago, it is now officially on CRAN. So you can go and use it. It's awesome. But I want to say here that the benefit is not so much the package itself, but just the courage to learn package development. I had a mental block with doing package development until I changed the motivation behind why I was doing it. It's just something that I loved.

Generative art and data science

Okay. So now that I've gushed about how much I love and benefited from Genitive Art, let's switch gears and quickly remind ourselves of what data science is. I'm not going to spend too long on this. So data science is a field that uses statistics, computing, methods, processes to extract and derive knowledge and insights from data. Honestly, all that to say, we're just going to focus on the coding and programming part of it, maybe a little bit more abstract, whatever, but this is what we're talking about.

Okay. So now that we're all on the same page about what data science is, let's get into some examples. Now, I have tons of examples, but I'll only focus on three main concepts. So how this will work is I'll present the concept first, and then I'll give an example of its use in an art scenario I had on maternity leave and a data science scenario I had when I returned to work.

So the first concept I want to bring to you all is iteration. So mastering this in art and data science can be a huge feat because it's an important concept in both fields. There's so many scenarios where we just want to do the same thing over and over. I don't think we can deny that iteration really tends to take people into that next level of skill because it allows you to do so much with less. So while on maternity leave, I had a task where I wanted to create lots of copies of a shape, but I wanted each shape to have a different color, a different size, and a different position on the coordinate system. Then, back at work, I wanted to summarize, label, and save multiple process data sets all at once. So these scenarios look a little different, but these are actually both just problems of iteration.

So the approach for both the scenarios is just to isolate the problem. So in the art scenario, isolation looked like figuring out the data, like how the hell do I make that little finger shape or whatever that was. In the data science scenario, hopefully your data is clean and good. So isolation would just more look like getting your processes to run on at least one data frame at least once without any issues. So the solution across the scenarios is the same as well. Simply use your preferred method of iteration to create a workflow. Once you've isolated the problem, the challenge is just to successfully introduce iteration. Now, I will point out that my preferred method is using per functions in R, but whether you're using per in R or for loops in Python, all that matters is that you're doing what you need to in a way that works for you.

Okay, so if we're doing iterations naturally, what comes next is development. So 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 because it allows you to take more advantage of the open source paradigm that we have within our community by creating programs for not only yourself, but for others as well. So while I'm a tourney leaf, I needed to create a function that spits out a color palette based on input choices. And back at work, I wanted to create a function that left joined a table of existing data to another data frame. So these are two different things, but the process for tackling both is very similar. In the art scenario, I just wanted to reduce that code bloat to just stop copying and pasting things over and over. And in the data science scenario, I just needed to make a new function that worked because one that we had just like stopped working as intended. So the approach again is the same, to isolate. How do we handle the input of the function? How are things moving through it? And what's coming out? So no matter the scenario, whether it's art or data science, you have to go through an iterative process of debugging and development to try to create a function that is hopefully efficient and runs as intended.

So whether you're doing art or data science or using R or Python, the goal of creating functions and doing development is the same. We just wish to do a specific task in an isolated environment for a consistent output. Also, creating functions is really like the gateway into a slippery slope of other crucial development things like unit testing, package maintenance, but I don't have enough time for that.

So the last concept I want to bring to you all is communication. So honestly, like, I think it's abatable if you need communication for art. I mean, like, if you're explaining art methods or collaborating with others' words, Megan, I'm sure. But for data science, nah, fam, don't get it twisted. You need to communicate or else. It won't be good if you don't know how to communicate. So even though it's not required for art, I did get to practice this skill out a bit on maternity leave. So on maternity leave, I needed help developing unit test suites for art functions in my package, and back at work, I needed to perform a data request for a stakeholder. So comparing these scenarios are interesting, because in the art scenario, I am the subject matter expert that needs programming help, and in the data science scenario, I am the programmer that helps the subject matter expert by giving them data. So both of these scenarios required communicating in different ways, but they both had that same need of getting everyone on the same page.

So as you might have guessed, the approach is the same between both scenarios, to just identify what matters. So this meant asking myself in the art scenario, what am I functionally trying to do without the context of the art? And in the data science scenario, this meant asking myself what external context or details about the data am I missing? So the solution, again, is to just take the right course of action to get the desired result. So in the art scenario, after I took that art context out of my question, I identified what I wanted to do programmatically, and this was actually the perfect opportunity for me to practice making reprexes, or reproducible examples, and I did so with the reprex package available in art. And for the data science scenario, I will say, if you're tasked with completing a request and you're getting too bogged down in the programming, it's a good idea to stop and ask yourself if you are missing any external context or info, and if so, step away from the console and go talk to your subject matter expert. I know that sounds scary, but we gotta do it.

Final thoughts

Okay, so I just rushed you all that. I do want to leave you all with some final thoughts. So this was a tiny introduction into the concept of just one type of generative art. This was personal. Generative art was my motivation to learn and do more. Doing something I loved made programming and data science digestible for me. So for those of you interested in generative art, I hope this talk gives you the push to open up your favorite IDE and try it out. For those of you that are not interested, I encourage you all to consider integrating a hobby or interest into your learning journeys. Managers and leads at work, could you make room in your team scheduling to allow for personal development that looks like this? Are you willing to let go of the belief that learning only looks like courses or textbooks?

Regardless of what you do after this talk, I want you to think about how different learning approaches may work for you. If you're currently having trouble understanding something, try to embrace learning in a low-stress environment fueled only by your interests. It may be hard, but try to let go of the notion that data science or programming can only be for profit or practical insights. Remember that we can conquer these beautiful but abstract challenges by transforming them into passions that we love. And if you're struggling with that fact, that's okay. Just give it some time and remember that it's all about perspective. Thank you.

Remember that we can conquer these beautiful but abstract challenges by transforming them into passions that we love.