R for the Rest of Us Podcast Episode 16: Cara Thompson
In this episode, I speak with Cara Thompson about color, delving into several aspects of its use in data visualization. Cara is a UK-based data visualization consultant with over 15 years of experience in transforming data insights into clear, compelling visual stories. We explore how she finds inspiration for selecting colors, her reasons for not simply using organizations' brand colors in her visualizations, and the importance of dedicating time to thoughtfully consider color choices in this context.
Connect with Cara Thompson on her Website, LinkedIn, X(@cararthompson) and Github (cararthompson).
Learn More
If you want to receive emails when we publish new podcast episodes, sign up for the R for the Rest of Us newsletter. And if you're ready to learn R, check out our courses.
Audio Version
Video Version
In the video version, Cara gives a walkthrough of code samples showing how she creates custom color palettes.
Resources Discussed
Transcript
[00:00:00] David Keyes: I'm delighted to be joined today by Cara Thompson.
[00:00:28] Cara is a data visualization consultant with an academic background specializing in helping research teams and data driven organizations turn their data insights into clear and compelling visualizations. She lives in Edinburgh, Scotland with her husband and two daughters and Cara regularly shares. shares coding tips for data viz online, and genuinely enjoys helping others level up their data viz skills through talks, bespoke organizational training, and one on one coaching.
[00:00:56] So Cara, welcome and thanks for joining.
[00:00:59] Cara Thompson: Thanks for having me. It's great to be here.
[00:01:01] David Keyes: Great. And I should also mention, um, Cara, you've, you've done, uh, work with R for the rest of us, um, in the past, um, I was I said to you before we got on the call, I've been really excited to watch you, um, you know, build your own business, um, which has been great to, to see as you've done that. A little sad for me because it's mean, it's meant that, uh, I've had less of your skills, uh, available to do R for the rest of us stuff, but, um, I'm excited to chat with you.
[00:01:29] Well, I'm excited to talk with you, Cara, about, uh, all things color, because one of the things that you've really gotten into is thinking about how to use color in plots.
[00:01:40] Um, so why don't I just dive into the first question?
[00:01:43] I think when people think about colors, you know, if they work for an organization and they're thinking, okay, well, we want to make data viz, the natural kind of first step would be great. Let's use our brand color. So, you know, if you have like a blue and orange, great, throw them in, make some plots. But I know that you've talked about why you can't just kind of take brand colors and, and use them directly in data viz. So can you talk about why that's the case?
[00:02:10] Cara Thompson: Yeah, sure. Um, so yeah, I think brand colors are always a good place to start if you're looking to create visualizations for your organization. But there are a few, a few things to look out for. One is that they haven't always been designed with accessibility in mind. Um, and so if you're, you know, I remember a project that we worked on together, David, where there was, I think there was an orange and a blue.
[00:02:32] And that when you put them through a colorblind test, they actually looked very similar to each other if they were done just in grayscale, for example. And so you want to be a little bit careful about just taking your brand colors because it might mean that the plots actually don't work for quite a large group of people.
[00:02:51] The other reason why you might not want to just use your brand colours is you might need more than the brand colours that you've got. So, say you're working for EasyJet and they want you to do some visualisations of their data. If everything is orange, that can be a bit overwhelming, and you might need some more colours than that.
[00:03:05] So, yeah, one of the challenges that I really enjoy is taking a brand colour, And figuring out how we can build that into, um, a palette, um, of the number of colors that we need that work within the accessibility guidelines, um, and that also help us convey the, the story that we want to convey.
[00:03:23] David Keyes: So in cases where, um, you know, you say you don't have brand colors or, or even I guess maybe when you do, how do you get inspiration to come up with color palettes that are going to work well for data viz?
[00:03:37] Cara Thompson: Yeah, good question. I mean, there's lots of different things that you can do. Um, in terms of general inspiration, I like hanging out in art galleries, um, just there's something really inspiring about seeing, seeing how artists have gone about combining colors. People whose specialism it is to you know, to create beautiful visual things or visual things that are really striking.
[00:03:58] So that's a general source of inspiration that I would recommend to anyone. I find kids books, you know, I read a lot of books to my daughters, and I guess because of the way that illustrations are done in children's books, and the colors are often quite vivid, and that's quite a fun source of inspiration as well.
[00:04:18] But if you're talking specifically about a project that you're working on, um, often there are colors that you can go to that will be tied to the project. Um, so for example, um, I've done this a few times when I've, uh, created a story about the penguins. So the, the palmer penguins is a data set that's used quite a lot in data science, um, to, to demo a few things.
[00:04:39] It's a really fun data set to use because of the correlations that are, that are inside it. And so I tend to invent little stories about the penguins, uh, baking things. Um, and I, I, I've done this thing a few times where I show a plot with default colours, Um, and I ask people, you know, which penguins were baking with ripe bananas, Which ones were baking with overripe bananas, And which ones were baking with underripe bananas.
[00:05:02] Um, and if you colour it, you know, green and yellow and brown, Uh, then it's obvious which ones which. Now that's a bit of a literal, uh, and understanding of how colors can, can map onto things, but sometimes starting with thinking about the concept that you're talking about and what colors are associated with that can be, can be a great way to, to start.
[00:05:25] Does that make enough sense or shall I elaborate? Yeah,
[00:05:27] David Keyes: no, definitely, definitely. And that's great because I think, you know, for a lot of people when they start out, if they're thinking, okay, you know, I have to come up with a color palette, like where, where do you even start? You know, infinite colors, potentially. So, you know, how are you gonna, how are you gonna decide what to use?
[00:05:44] I think looking at, you know, books, say, or art galleries, or I know you've also talked about using photos. I'm curious, like, how, how you would look at a photo, say, and use that to generate ideas, and why you think that that type of approach works.
[00:06:04] Cara Thompson: yeah, so I can, I can show you a photo that I've used as inspiration for a palette for a project. You can see, um, here is a photo of a mountain, um, in British Columbia, um, and this was for a project, uh, where the, you know, the person that asked me to come up with the color palettes was coming up with a system, um, in which he needed different users to have different views, um, and we needed to make sure that it, it kind of made sense to, to the semantics of what was going on.
[00:06:34] And so there was an old system that we were going to be trying to replace. And so that was represented with the kind of shadowy purple colors that we have here. And then we had the new system, the new growth. So we went for green to represent that. And then I wanted to kind of honor the people who would be using the system who were mostly the administrators involved in the project.
[00:06:56] But they were the ones that had the bird's eye view of the whole thing. And so I wanted to put them at the top of the mountain. And so we kind of picked a color from the top of the mountain to illustrate that. And then the final color was the color associated with the group that he was looking to create the system for.
[00:07:14] And so here are the colors that we ended up with. Um, which, you know, they, they work quite nicely together, and I'll, I'll come into a little bit more about how we can achieve that. Um, but when I talked about, you know, picking colors, obviously you're not going to create plots always that are about literal things.
[00:07:30] So you can be a bit more creative in your interpretation of which colors are going to work well, um, for the plots, um, um. So another fun one, um, there's a paper that's just been published actually, for which I did the visualizations, in which the authors were comparing how trustworthy news videos were, based on whether they'd been entirely created by a human, or if there'd been some AI involved in creating the video.
[00:07:52] Um, and so for that, I kind of chose a pinky orange brain color, and then, to be the human made stuff, and then a steely blue to be the computer made stuff. And then you kind of know that between pink and blue you end up at purple, and so for the videos that were made partly by a human and partly by AI, you have a color that is interpretable straight away.
[00:08:14] So those are the more, kind of the less literal versions of taking a photo or an idea and bringing colors from that.
[00:08:23] David Keyes: It's, it's interesting because, you know, I think, People, and myself included, would think about, okay, coming up with colors, like, I just need to think of what colors, like, look good together. But you're kind of taking a different tack, where you're saying, well, let's, you know, look at a photo, and obviously that photo of the mountains and the lake that you showed, like, it's gorgeous, right?
[00:08:45] And so you kind of, by choosing colors that show up in that photo, So, like, in some ways it seems like you're more likely to get colors that play well together because they, like, it looks, it looks really beautiful in the photo, so then the colors will likely, you know, look good, uh, on their own as well.
[00:09:04] It's just an interesting, like, it's a, it's an indirect approach, but it seems like it yields good results and, you know, avoids you potentially just being overwhelmed trying to think again of, like, how can I choose some colors? Um,
[00:09:16] Cara Thompson: Yeah, exactly,
[00:09:18] David Keyes: approach.
[00:09:19] yeah. Um, one other thing you've talked about is designing with accessibility in mind.
[00:09:25] I know you talked about that briefly, uh, a few minutes ago, but you've also said that designing with accessibility first can actually be, have, have benefits for all audiences. So I'm curious, like in the context of color, what does that mean and, and how do you kind of, how do you see that playing out?
[00:09:46] Cara Thompson: good question. So, in the context of colour, um, there's a bunch of recommendations that come, uh, to, to make things accessible. And, um, they have positive consequences for, for everyone. Uh, one of the, the, the recommendations that I, um, personally really resonate with, um, is that if you just, if you're just using primary colours, so a kind of really bold red, and a really bold green, and a really bold blue, Um, you know, the ones that you get if you, you just type red, you know, CSS, red, um, it's really overwhelming to look at, um, because those colors are just, they're just really in your face.
[00:10:27] Um, and so one of the recommendations is to use, uh, kind of slightly blended colors so that you don't end up with that really hard hitting color, which, which I think, you know, you, you'll, you've all come across a website that you open up and you think, gosh, this was designed when colors were a really big thing.
[00:10:43] Um. And it's just really difficult to read, whereas if you go onto a website where things are a little bit more muted, um, it's easy. Now that's not to say that it needs to all look like a 1970s film, uh, where everything is just that slightly, you know, greyish colour. Um, no, you colours within that. Um, but if you try and kind of blend in a common color, um, then that tends to, to do the trick, which, you know, I created a package to do that, uh, called monochroma, which we can, we can talk about as well if that's of
[00:11:15] David Keyes: Yeah. Well, before we get into that, I, this actually is kind of a little bit out of the blue, but I'm curious where your interest in in colors in general comes from because, you know, you, your PhD is in psychology, right?
[00:11:31] Cara Thompson: Yeah,
[00:11:32] David Keyes: And, you, you know, that, people with that background, I mean, you don't have like a, you're not like a You don't have like an art PhD, say. Um, so I, I'm just curious because I don't think it's, you know, super common for someone with your background to have as strong an interest in colors. So yeah, can you talk a little bit about where that comes from?
[00:11:53] Cara Thompson: yeah, good question. I mean, I think I've always been interested in how the brain processes stuff, um, so I grew up in a French speaking, uh, an English speaking family in France, um, so I, there were two languages going on, and everybody plays a musical instrument. So there was, there was music, there were two languages, and, and somehow we were all making sense of this.
[00:12:15] You know, when you think about it and you reduce it, it's just noise, but that, you know, at the moment you and I are just exchanging sound waves, um, and yet it's communicating stuff from inside my head to inside your head, and I've just always found that fascinating. Um, and I remember, it maybe comes from that thing of growing up with two languages, that you have an appreciation of the fact that the world Sounds and looks and feels different to different people.
[00:12:39] Um, and I remember very early on asking, you know, how come if we're talking about the color orange, do I know that you are seeing the same thing when I'm saying that, you know, you know. Um, so I think it's more just a general interest in how other people perceive the world, um, and how we can make sure that communication is optimized, um, across different contexts, across different, uh, you know, perceptual idiosyncrasies.
[00:13:04] Um. Yeah, It's just something that's always interested me. Um, and then the effect that you get, you know, if you, if you're going through a tunnel and there's funny lighting in it, you still know what color things are because you're, you kind of do some kind of interpretation on that. Um, so yeah, it's just, I think, parts of it is just curiosity.
[00:13:23] Part of it is, um, wanting to make life as easy as we can for, for as many viewers of our visualizations as we can. Um, yeah. And part of it is that, frankly, I just think it looks better when, when you take this into consideration. Um, you know, I didn't, you know, we talked about the muted colors and, you know, all the blended colors.
[00:13:42] Um, the other way in which it helps everybody is if, you know, you bring your paper to somebody and they print it off in black and white, then they've got to still be able to read the plot. Or if you're presenting at a conference and the, this, you know, the projector isn't great quality and that kind of messes up your visualizations, if you've optimized it.
[00:13:59] So that people who sometimes struggle with colour can see it as best they can, then it kind of helps you with all those different contexts as well.
[00:14:09] David Keyes: Yeah, that makes sense. I know you've also talked about using color, um, as a way to be kind of less dependent on annotations in data visualization. Can you give an example of, of how that might be the case?
[00:14:23] Cara Thompson: Yeah, sure. Um, so I think there's, there's two ways in which it can be the case. One is that it helps you remember what's what. Um, and the other is that it helps you process a plot more quickly, so you don't actually have to read the annotations as much. So I'll just share my screen and you can see what I mean.
[00:14:42] Right, let's do a quick test. So here we're back at the mountain that I showed you earlier. We're going to do a quick test. I'm going to ask you in the next, the plot that I'm about to show you, which is the second ingredient from the bottom. Okay, here we go.
[00:14:57] Cara Thompson: Okay. Um, so the options were chocolate, raspberry, sponge, and rhubarb. So we'll just go again. So here's the next plot. Okay, there we go. Um, if instead, I show you this one, and then we go back, you can see, you can remember much easier which ingredient was the, the one that was second from the bottom. So in this plot, the colors are very literal.
[00:15:25] We've got a chocolate color for the chocolate bar, we've got a raspberry color for the spongebob. And we've got a rhubarb color for the rhubarb bar. Um, and that means that you don't really need to read that it says chocolate, raspberry, uh, genoise, or sponge, and rhubarb, because it's kind of there already in your mind.
[00:15:43] Um, and when you walk away from the plot, um, you'll be able to remember that, you know, raspberry was the second one. Gin was the third one, etc. So, um, whereas if you create the plot like this, the colours work really well together, they look really nice, but it's much more difficult, um, you know, two days post conference, someone says, what was the second bar again in that plot?
[00:16:03] You have no idea. Uh, whereas if you do this, then you'll, you're probably more likely to remember. Um, so that's a way in which I think they can make a, a bit less dependent on annotations, um, in that they make the legend, Not redundant, but they make it easier to remember what's what.
[00:16:20] David Keyes: Yeah.
[00:16:22] that's interesting. Um,
[00:16:27] Cara Thompson: I
[00:16:27] David Keyes: cool. Well, one of
[00:16:28] Cara Thompson: I wouldn't recommend doing a rainbow bar graph all the time. So,
[00:16:32] David Keyes: Okay.
[00:16:32] Cara Thompson: bars are just there to demonstrate stuff. Someone pulled me off on this online. Yeah, it's true. If you, if you create your bar graphs and every bar is different, then that's maybe not the best use of color, but this is just to illustrate that if you then had a, you know, a scatter plot somewhere else, or And, you know, some trend lines.
[00:16:48] If you've identified a clear colour that's related to the concept that you're interested in, it's so much easier to remember what's what.
[00:16:55] David Keyes: When that sort of gets at, I know you've talked, um, you know, in various places about the idea of color semantics, it seems like that's sort of getting at that, right? Like the idea that you choose a color not just because you think it looks nice, but because it actually kind of represents something, like red for raspberry or whatever.
[00:17:16] Cara Thompson: Yeah. Yeah, exactly. And then whether that's literal or more metaphorical. is just making sure that you're not bringing too many cultural assumptions into what other people associate with that colour. Um. And again, being mindful of the main audience for your visualization, um, because that might influence the, the colors that you're going to be using there.
[00:17:39] David Keyes: Interesting. Have you had examples where you've chosen colors or maybe seen other places where people have chosen colors that are, you know, work well in one particular cultural context, but, but don't translate as well to other contexts?
[00:17:54] Cara Thompson: It's not, it's not something that I've really done myself, but I was just, you know, talking about this in a seminar recently and someone brought up that point, um, and also talked about, you know, they were creating graphs about, um, kind of climate change issues and looking at intercultural interpretations of the concept of Mother Earth, and the colors that were associated with Mother Earth were quite different in different cultures, and, um, the need to be mindful of that if you're, if you're creating graphs that have got, um, those strong, strong messages within them.
[00:18:25] Um, yeah, I mean, the other place, Where I've seen, uh, that this can backfire, it comes back to your question about why not just use your brand colours. Um, that if you're, say, telling a story about different demographic groups and your logo is mostly green, um, the group that you make green, you're kind of saying is the main group in what you're talking about.
[00:18:46] And so, um, it's worth being mindful of that as well. Um, when you're, if you have one main brand colour, which group do you associate it with? Or do you associate it with a group or do you just try and And instead, blend it in a little bit to the other colors that you're using.
[00:19:03] David Keyes: Yeah, it's interesting. I mean, there's so much, you know, just talking to you and you and I have talked in the past about color, but even now I'm realizing like how much thought, um, is involved in kind of developing, Palettes and yeah, how, how, how far it goes beyond just, you know, use your brand colors.
[00:19:21] Um, I know that one thing you've done because you work with organizations to help develop kind of, um, like data viz design systems.
[00:19:29] That's what you call it, right?
[00:19:31] Cara Thompson: Yeah.
[00:19:31] David Keyes: Um, so one thing that I know you do Do both, I assume, in, in developing your own, data viz design systems for organizations, as well as, you know, showing other people how to do this on their own, is you've developed, um, a package called monochromer, which helps to, with the development of palettes.
[00:19:50] So, um, I'd be curious to have you show up, but even before we actually have you kind of show what the package does, can you talk a little bit about the package and what the, the idea behind it is?
[00:20:03] Cara Thompson: Yeah, the package mostly grew out of me wanting a shortcut. So I was creating visualizations as part of Tidy Tuesday, which is an online challenge where somebody releases, It's a data set in which you can't, you know, you can't really put your foot in it. It's a data set about stuff that's, um, you know, innocent.
[00:20:20] It'll be coffee ratings in a, in a coffee competition or it'll be, you know, pets that have been found at various places and locations. So it's, um, it's stuff where, yeah, it's easy to make graphs and to practice because nobody's going to be making a life decision based on these graphs. But anyway, I was, I was taking part in the challenge.
[00:20:36] Somebody mentioned using monochrome color palettes and, um, I was like, okay, I was going on to, um, you know, HTML color websites and looking at the gradients and picking them and copying them across. I thought it'd be so much better if I could just do this all within R. I bet there's a package for that, and there wasn't, so I thought, okay, well, I'll write it then, um, and see where we go from that.
[00:20:57] So, the, the idea behind monochroma is that you take a starting color and you go darker from there, or you go lighter from there, and it gives you a range of colors, and you can specify how many colors you need. Um, that was really the, the starting point for it. Um, and then from there, I've ended up using it, um, in creating color palettes for clients to, to blend in a bit of the, the client's color, um, and also to teach people about, you know, if you've got, if you're not starting from a photo and you're starting instead from colors that are in your mind, um, that you think are good for the, the concepts that you're talking about, then blending in a little bit of the extra color, uh, can, can help it all work nicely together.
[00:21:36] Yeah,
[00:21:39] David Keyes: no, that's not true, I have used it once. Um, but my understanding, um, based again on limited use, is it can also help you to avoid, you know, instead of using like the html red, which will burn your eyeballs because it's so bright, it allows you to kind of, you know, blend in colors to make them, you More appropriate for, for database.
[00:22:03] Is, is that an, am I remembering accurately that,
[00:22:06] Cara Thompson: yeah, yeah, yeah, absolutely. Yeah, I mean the, when I first created it, it was literally just, I want gradients of this color. Um, but the more and more, the more I use it, the more I use it for exactly that purpose of blending colors to make them, make them look nicer, make them on brand. Um, and also I use it quite a lot to, um, change the text color around a plot as well.
[00:22:29] So I have a dark text color and a light text color that are based. Typically on one of the colors that's inside the plot. Um, and that all comes from using monochrome as well.
[00:22:38] David Keyes: Cool.
[00:22:39] Um, yeah. So why don't you just show us how the monochromer package works?
[00:22:44] Cara Thompson: Sure, yeah, happy to. Um, so, let's say, um, that you We're going to start with the after the rest colours, so we know what your hex code for your colour is, so we're going to just pop that in here, and generate palette, so we said it was 6abdd,
[00:23:07] no 6ca, there we go. So we've got the after the rest blue, um, and then, Let's say we want to have a green color that is kind of related. Actually, no, first let's just start with the simple go lighter or go darker thing. So we're going to go darker from here. Um, and we are going to say that I need five colors.
[00:23:32] Um, and I want to see what it looks like, um, in the, the plot window down here. So I'm going to say, oh, true, if I can spell that properly. Okay. Um, and then it gives me, um, five colors that are here, that are the colors that I've asked for. Um, and we're starting with the after the rest blue, and we're going darker, um, as we go.
[00:23:56] Um, and so, you know, this is just a simple way of getting a gradient of color palettes. Um, I tend to use this quite a lot to create a dark text color. Um, and then what I would typically do is take that dark text color. So I would copy that. And then pop it in here, and generate a palette where I go lighter, um, and then that would give me some colors.
[00:24:26] There we go. And so then that gives me some colors that I could use. Say, this would be the dark text color, and this would be the light text color. And you might want to change, you know, the number of colors that you create, um, so that you've got a bit more, um, Variation there if you want to.
[00:24:41] Obviously we've zoomed in quite a lot so it gets messy with the labels. Um, and if you want to switch the labels off, then you can do that as well. Um, if you just want the color palettes. Um,
[00:24:54] David Keyes: So
[00:24:55] just, you went from the brand color, the blue, and then you used it to generate that kind of gradient that you would potentially use if you were doing some kind of, you know, working with some kind of continuous variable. Would you use the first one that you did? Would you, the first palette that you made, would you use that ever for discrete data, like for categorical data?
[00:25:21] Cara Thompson: you could do, it depends what you're talking about. So if you're talking about categorical data where you've got, say, one group that you want to really highlight, um, and the others that should just sit in the background, then you could do that quite nicely. Um, yeah, if you wanted to create a bunch of different discrete colors that are all, um, on brand with the after the rest blue.
[00:25:42] And then what we need to do is feed it a blend color instead of just going darker or going lighter. And so again, we can, we can do that. We change this here. We'll say blend color equals, and then we'll go with green because that's That's always fun. So this is the, the really bright, um, kind of CSS green that we talked about earlier.
[00:26:02] Um, please do not use this as is in your visualizations, um, unless there's a very strong reason for it. But yeah, people will need to get their sunglasses out. Um, so we've blended a color in and so it tells us, um, that it's blending. Um, and then we get these ones. so then the fun thing that you can do is that you can It always keeps a little bit of the initial color in here. So we've got the R for the rest blue here, and then we've blended it with the green. Okay, so then I think this middle color here is quite nice. If you wanted a kind of on brand green that you could use.
[00:26:35] But just to show that it keeps a little bit of the R for the rest color at the end, I'm just going to copy this one here. And then we're going to see view palette and pop it here. And you can see that they're a bit different from each other. Um, and also that the one that's got a bit of the after rest blue in it is, it's just a bit less aggressive on the eye than the one that doesn't have anything blended in.
[00:27:00] Um, so yeah, so I use this quite a lot, um, in, in creating palettes, uh, for clients. You know, sometimes you might start with something a little bit nicer, like, you know, dark green. Um, and you can, you can create some really nice colors, uh, because they're, they're blending it in. Um, and then if you say you've got a green one that you're using like this, and a purple one, um, then combining the, the green and the purple together, um, if you, if you were to take them and they've both got a bit of the, half of the rest blue, then they should work, um, together as, as colours and not jar too much.
[00:27:36] David Keyes: That's interesting. So by by combining that blue with you know, the green and the purple you can get a version of green and a version of purple that will look kind of harmonious with the, the, the blue color and not just, you know, the bright green or the bright purple.
[00:27:56] Cara Thompson: Yeah, exactly.
[00:27:58] David Keyes: I never thought about that as a way to, to, generate colors that, that work together well, but
[00:28:04] Cara Thompson: Yeah, I mean, we can test it, right? So we've got that, and then if we swap in, this purple here, and then we'll grab the green that we created, say this one here. We'll see if the theory holds out, but we should get three colors, um, oops, let's put it inside a vector. That's why that didn't work. So we should get three colors that work together, um, that you could, you could use in your visualizations.
[00:28:37] Um, yeah.
[00:28:39] David Keyes: really cool.
[00:28:41] Um, okay. So how, you know, if you've made, a palette and you're happy with, you know, say your blue, green, and purple. How do you implement this in code? Because you don't want to have to just remember those hex codes. Like, how are you going to actually write some code that that makes it reusable?
[00:28:59] Cara Thompson: Yeah, good question. Um, there's several ways of doing it, but the, the easiest way to do it, um, I think we'll just demo if I share my screen again. Um, and then you can, we can walk through what I'm doing. So we're back in the, our studio, um, view, and you've got the, the colors that we've selected that we've come up with just here.
[00:29:21] Um, and now we're gonna create a plot. So we're gonna upload, uh, Gigi Plots, and I'm using the Palmer Penguins Library, which contains the Penguins dataset, and we're piping that into Gigi plot. And then we are creating points that correspond to the length of their bills and the length of their flippers.
[00:29:39] And the size, and we're going to color them, um, by species. Um, and let's just create that and see what that looks like. So, it looks kind of messy because the, it's all zoomed in. But you can see that we've got three different colors here that correspond to three different species of penguins. Um, the easy way, uh, well the quick way to add colors, um, is to go to scale, color, manual.
[00:30:09] values equal, and then we would just grab the colors that we had earlier. So I'll just grab them here.
[00:30:21] And how many do we plus at the end?
[00:30:27] And nope.
[00:30:28] David Keyes: think you need scale fill manual.
[00:30:30] Cara Thompson: We need scale failure, right? There we go. Okay, so there we have a plot, um, with the, the colours in it. I'm just gonna get rid of the green background, because that's always a good idea as well. Um, and it'll look a bit nicer. So, there we go, we've put the, we've put the colours in. Um, I'm gonna make the outline white.
[00:30:54] Because that'll look a bit nicer, um, as well. And then we've got some, some colours in here. So, the The good thing about this is that it's quick and easy. The dangerous thing about it is that if someone comes around and messes up the order of the factors of the species in your dataset, then it messes everything around.
[00:31:14] So let's just demonstrate that. If we do mutate, species equals factor species. And we'll just put them the wrong way around. So at the moment, we've got the Gentoo as green. Uh, and well, it's easy to remember because they start with the same letter, which is another trick. If you're struggling to come up with colors, just come up with a color that's got the same starting letter as the thing you're trying to describe.
[00:31:39] So if instead, we make the Gentoo the first one, and Adeles, and then Chinstrap, which are the three species that we know are in the data set. and that's it. Um, I think I need to close another bracket somewhere. And if we run that again, um, then the gen two now have become blue, whereas previously they were green.
[00:32:08] Um, and this can be really problematic because I, things change in data datasets all the time, and you might be collaborating with people, then somebody comes along and changes, uh, what order the factors should be in, and suddenly your colors don't align anymore. So. The way to avoid doing that is to create a named vector instead.
[00:32:27] So we are going to say that the deli penguins are the after rest blue, and then we're going to say chinstrap are the purple, I think that one is, and then I'll put the gen2 at the bottom here. And if we run that again, they should be back in the order that they were in. Yeah, so the gen2 and R are green.
[00:32:54] Um, even though they're appearing top on the list, the colors are staying consistent with what we had already decided that they should be. Um, so that's great, but this is a lot to type every single time you're creating a plot. If you're reusing it within a project and say you've got, you know, 12 plots that you want to create that all use these colors.
[00:33:13] So instead What we're going to do is we're going to copy this above, and we're going to say these are penguin colors. And that's our name vector here. And then every time we want to create a plot, all we need to do is put that here, and then it will reference the colors that we've got. And ta da! It all works.
[00:33:38] So, um, that's one way of making sure that your colors get pulled into the plots consistently. Um, it's to set them up as a named vector where you're matching it to the different levels of your factor. Um, and then you can make sure that it will always be exactly where it needs to be.
[00:33:57] David Keyes: Yeah, that's great. And I know we won't get into it today, but I know, you know, another thing that you do, especially in your consulting work, is you actually put this type of code into packages for organizations who want to, you know, have even more, uh, even simpler ways to, um, um, reuse that type of code.
[00:34:17] But I think
[00:34:18] that's a, that's a good example of how, you know, in a relatively straightforward way you can, um, apply your palette to a plot.
[00:34:26] Cara Thompson: Yeah. Yeah. And then, you know, we talked about moving the theme and again, creating a theme that ties in with the colors that match the concepts that we're talking about and the client's brand. Uh, you know, that's, that's a huge part of the, the system as well. I
[00:34:41] David Keyes: Yeah. Yeah. Um, cool. I know you've actually made a package for a client. Um, the package is called Ophelia where you, um, implemented their brand colors. So can you show kind of what it looks like once you've implemented it into a package, how, how you then apply it to a plot?
[00:35:01] Cara Thompson: Yeah, sure. Yeah, I gave a talk about that. I think it was at our medicine last year, and it was just really fun being able to show people the before and after, and the process of working through that. We can maybe pop a link somewhere to that if you
[00:35:13] David Keyes: Yeah, I'll put that in the show notes.
[00:35:14] Cara Thompson: Um, but the, so here's, here's our basic.
[00:35:17] ggplot, um, as it comes out of ggplot, um, and obviously, you know, again, it's all zoomed in, so it's a little bit messy, um, but the, the first thing that we can do is with the Ophelia package, um, is that you then say theme Ophelia, um, and that just one line of code changes, uh, what this, what this looks like.
[00:35:40] Let me just get rid of the subtitle because I think this is confusing things. but part of the fun with the subtitle there is that it just fits within the plot. You don't have to figure out where your line breaks are, which is always a bit of a headache when you're creating plots in ggplot. But it's all popped inside a text box.
[00:35:56] So that's done the, it's changed the font, it's changed the background color, it's changed, it's got two different fonts going on and different text colors as well. And then we can do this, and we'll go etherea, scale, fill Ophelia, um, and that will bring, um, the Ophelia colors into the, the penguin species, um, that we had set up there.
[00:36:20] And then there's different ones that we can try, uh, you could go for cool colors, uh, let's imagine that the penguins are all pretty chilly, uh, we can do cool colors. Uh, if we want some warm penguins, then we can do that as well. Um, and yeah, it's I really enjoy, um, creating these because Well, it just takes the headache away for the client if all they need to do is add two lines.
[00:36:44] Um, and everything's been thought of for, for where it should all fit. Um, yeah, it's just really satisfying to know that it's liberating them to spend their expertise on, on other things.
[00:36:54] David Keyes: Yeah, definitely. Um, cool. But yeah, we'll definitely put a link to that talk you gave, because I know you go into it in, in even more depth. Um, and it's just interesting to see, you know, like we've been talking, it's the combination of first coming up with a palette and then thinking about how to implement it in code.
[00:37:12] And I think that's, you know, kind of your, your special sauce is
[00:37:15] that you can do both of those things, um,
[00:37:17] which is pretty cool. Um, So, one common response that I think, especially among kind of like hardcore gamers, Data people, not all, but some, will be, it's not worth it to spend this much time thinking about, you know, the aesthetics of your, of your plots.
[00:37:34] Like, colors aren't going to really make an impact. So I'm curious when you hear that type of critique, what, what's your response? How do you, how do you respond to that?
[00:37:44] Cara Thompson: Yeah. I think. That kind of critique is, is difficult to challenge because in some senses, you know, if all you want is something functional, then you might think that the colors don't matter. But actually, the colors are so much more than just making it pretty. Um, you know, we talked about accessibility a lot of the time.
[00:38:00] The default colors that people pick are not necessarily easy to see for everyone in the teams. You know, one of my friends works in a team and is very conscious that the default colors that come out in the, in the stuff is not accessible to his colleague who's colorblind. Um, and so it's just, It's really interesting that what is perfectly fine and functional for somebody might not be for someone else, so there's, there's an empathy side to it.
[00:38:22] Um, but actually the colors do make it more functional. They, they help you remember what's what, they help you, uh, when you're creating your visualization to, to not have to, you know, spend too much time, you know, if you're, if you're checking, did that, is that data point in the right place? Wait a minute, which group does that belong to?
[00:38:38] Um, you know, I was doing that earlier and. And I was jumping between the data set and the plot and the data set and I was like, no, let me just put some sensible colors in here and then I'll be able to see what's going on and that'll, that'll make it easier for me in creating it. So I think, um, while it feels like an unnecessary investment of time to come up with these things, it actually ends up saving you quite a lot of time in the long run because it saves you time checking stuff, it saves you time interpreting stuff, it saves your readers time interpreting it as well.
[00:39:07] Um, so yeah, it's not just about making it pretty, it is about making it a lot more functional than, than it currently is.
[00:39:14] David Keyes: Yeah, that's great. Yeah, and I think that idea that, you know, maybe you spend More time up front coming up with, you know, thinking about what, what's an effective color palette for your organization. Um, Obviously that's going to be more time than just, you know, slapping on scale, fill, whatever. Um, but in the long run, I mean, in some ways it's like similar to learning R, you know, because I always tell people when you're learning R, it's going to, you're going to be a lot slower initially in R than with Excel or whatever other tool, but the more you do it, the more efficient you'll become.
[00:39:48] And it seems like it's a very similar situation with developing a color palette. Yes, it might take a little longer. To come up with something effective, but in the end, it'll save you time and of course be, you know, colorblind friendly, be better at communicating and all that. So,
[00:40:05] um, great. Well, last question.
[00:40:08] Um, so you, I think we've established, um, care a lot about, um, the aesthetics of colors, you know, thinking deeply about colors, but if someone is not, um, you know, as. invested in that process or, you know, wants to, to use better colors, but doesn't, um, go to, to art galleries and think about how they can apply those colors to their, to their plots. I'm curious if you can give, you know, maybe two or three tips to help them think about how to use color more effectively in their data viz.
[00:40:42] Cara Thompson: Yeah, sure. Um, so I guess. If you're really not interested in what it looks like, but you just want to make it functional, uh, then pick a color that starts with the same letter as the, the level that you're talking about. Like we did, you know, we made the gen2 penguins green, and then it was really obvious that something had switched in the plot when we were looking at the second time around.
[00:41:03] Um, so yeah, that, that's a very functional way to do it. Um, I would say consistency is really important as well. So again, Even if you're not too fussed about the aesthetics of it, making sure that you've always paired the same colour with the same concept throughout your report means that people can easily jump to the thing that they're interested in looking at and not have to re learn with every plot.
[00:41:27] Okay, purple is this, but last time it was orange, and then it's going to be pink next time around. It just gets quite confusing. Being consistent, but also I would encourage you to think about the things that you enjoy visually, um, and, um, what makes you look longer at, uh, I don't know, a photo, um, or a picture, or a report, or a table, or a visualization, um, than, than looking at another one, um, it's probably because there's something about the, the composition of that, that, that you're enjoying, um, and so you ultimately, this is a word that I'm going to use, um, quite a bit, um, and, um, I'm going to say, You want people to be looking at the stuff that you're producing, you want people to be remembering it, and so it's worth, worth thinking about what might help them do that, and I think choosing good colors and good fonts, um, is, is an important part of that.
[00:42:24] David Keyes: Great. Um, well, Cara, thanks so much for joining us. It was really interesting. I mean, it's for me as someone who does think about color, but nowhere near as deeply as you do. I definitely learned a lot. So thanks again for joining us.
[00:42:36] Cara Thompson: Thanks for having me.
Sign up for the newsletter
Get blog posts like this delivered straight to your inbox.
You need to be signed-in to comment on this post. Login.