Transcript#
This transcript was generated automatically and may contain errors.
Today we are joined by our featured lab manager, Gina Reynolds, and I will also say our extra featured lab manager, Hassan Kibirige, and he will be joining us for the second half, I think. Gina, would you like to say hello?
Yeah, thanks for having me, Libby and Isabella. Yep, really happy to be here. So, I and others are joining kind of by way of a different community initiative, which is the ggplot2 extenders. So, some of our regular joiners are on the call. We did kind of like a rehearsal yesterday and a number of our folks got to that. So, we have them on call too. So, you can meet some of the ggplot2 extenders as well as tackle some extension.
Yeah, okay. So, here's what we're going to be doing today. We all know and love ggplot2. If you don't know and love ggplot2, welcome to the fan club. It is a package for R, for plotting in R that makes plotting accessible and magical and extremely accessible and sort of plain language, right? It lets you create plots the way that you want to speak them into existence by layering things on top of each other, layering elements on top of each other. That said, ggplot2 is a base package that can be extended. You can add functionalities to it with custom functions. You can put those custom functions in packages. And that is often what happens. And we are blessed in this R ecosystem to have so many packages that extend the functionality of ggplot2. If you've ever used something like ggforce or ggfx, like adding things, special things to your ggplot, you are using an extension package. So, that's what I wanted to start with today. What is a ggplot2 extension package?
And we are going to have Isabella walking through live coding an extension to ggplot2. Gina is going to help her drive. So, we're doing a bit of mass pair coding here, if you will, in R. And then also, if you are a Python user and you know about plotnine, you'll know that that brings the grammar of graphics, which is ggplot's underpinnings, to Python plotting. And we have Hassan here, who is the author of that package, who can also walk through the Python side of extending functionality for plotnine. I'm really excited about all of this. This means that I will be taking a back seat today. I will be in the Discord with all of you while Isabella takes over with screen sharing. So, this is what I will do. I will say, Isabella, would you like to go ahead and share your screen? And we can start chatting a little bit about the links that we're going to see today to some resources from Gina. That's what we're using. Some recipes to create extensions.
And it would also be great if we could all talk about our favorite extensions. Like, mine is geomtextpath. That's my favorite one. I'll add that in the Discord right now. If you have a favorite, please share it. And I'm hoping Isabella will share hers on her screen as well. All right. Take it away, Isabella. Maybe this is a good moment to make sure my sharing works. Is this okay? But just to briefly chat about my favorite ggplot2 extension package. It's called ggridges. And it does this really cool way of rather than a bunch of line plots that might be a bit difficult to interpret, it creates these kind of ridge-like sort of plots that then you can kind of overlap. You may have seen this to do things like visualize temperature or over time.
I think this is a really fun package. Gina, how about you? What's your favorite?
Yes. Well, I like ggbump a lot. I think that sits in my consciousness as like, oh, there is someone that is not like a full-time like posit employee that created a ggplot2 extension package that felt like really powerful. So, that was kind of an inspiration for me. Yeah.
Here's ggbump. It's so cool. Oh, this would be a really interesting one if we could do it with the soccer tournament that just finished. Yes. World Cup stuff. ggbump is so special. I don't know if anybody knows making bump charts is actually really difficult in other plotting modalities. ggbump does something amazing. Awesome.
Philosophy of ggplot2 extension packages
So, all of these packages that kind of exist, if you imagine somebody had to think of the idea, come up with the inspiration, and then actually do them. And Gina, do you mind if I turn it over to you to kind of talk about the philosophy of like how these even work and how to create them? Yeah, sure. So, I think there's kind of like two major classes of ggplot2 extensions. And so, some are like really practical and they just like want to do a specific job and they're like, well, we know how to use ggplot2. We're going to write a wrapper function that is going to get this task done for us. But other people are like more motivated by I guess the grammar itself and want to create functions that break out the different components. So, they really follow the pattern of creating functions that similar to those that we see in base ggplot2. So, like scale functions that we can apply independently. Scales, coordinates, geoms, scale, sorry, stats. So, all those independently declared components. And that's more where my interest is. I'm like inspired by what Libby was saying, you know, that incremental plot build. So, I guess that's the gist of the meeting.
And what we're going to focus on today is layer extension. So, and layer in the sense like the kind of original sense that layer was used. So, like in the seminal paper about the grammar of graphics, it's called the layer grammar of graphics. And that's to distinguish between Leland Wilkinson's grammar of graphics. So, layers in this kind of original sense talked about geoms and stats. These marks that would be applied onto the plot. So, I think the meaning has kind of changed now, right? So, we have all of the different components. We're like, oh, those are all layers. That's what Wilkinson meant. But like when Hadley wrote about it at first, it was like it was layer extension. You would think of stat extension or geom extension. So, we have like we think of scales as a separate type of extension. And I think like, you know, and this is a really powerful extension point. Like I'm thinking of kind of Cedric Scherer's work. He talks about his favorite extensions. A lot of them are layer extensions. So, and I think that's true of a lot of people. Like the layer extensions grab people's attention. They tend to give people a lot of power in plotting. And yeah. Did you want to jump in, Isabella? Oh, that's what I'm saying. Shall we show like what does it start to look like when we actually start to as we're building plots, like how we can actually start to build out this kind of layer extension?
Looking at the internals of ggplot2 layer functions
Yeah. I'll share my screen and I'll stop unsharing it. Sorry. It's a habit of mine. Yeah. Perfect. Yeah. So, I guess like a little bit of background, we can look at the internals of some familiar functions, probably to everybody that uses ggplot2. So, we're gonna actually like kind of borrow some of what's going on with geom point. So, let's look at the internals of geom point. So, if you just type, Isabella. Isabella's gonna do my typing. Yeah. Geom point. And then we'll erase the parentheses to look at the definition.
Yeah. This is a very cool way of just taking a quick look within a function and what it all entails. Yeah. And so, there's like actually a lot of infrastructure here. A lot of scaffolding. But like a main thing to notice is that this function wraps another function layer, which is the very general function for the like classic layer functions. And every layer function is gonna have three main characters is how I think of it. Okay. So, a stat. Here? Yep. And then a geom and a position.
Oh, right here. Yeah. And the geom that Isabella highlighted, that's hard coded. So, that's written out. Geom is gonna be point. And then the user could actually go in and change if they want to. Oftentimes, you just use the user facing function as is. They can change the stat. The default here is identity. And then the position is also identity.
So, just to confirm, this cannot be changed. It's built into how geom point is defined. But things can be. Right. So, those are what the user can modify. So, there's a default, but that can be modified. Point is kind of hard coded. So, there's like three main definers of every layer. So, stat is pretty much in this case with identity, it's not making any major modifications. Position also no modifications. And geom point we can think of as kind of the mark or the rendered ink on the page. So, the data's gonna flow through the layer. We will go through stat and then geom and then position, which might do a little bit of offsetting. Hassan said the position makes the rendered layer dance. It's often a handle over plotting or something like that. But let's have a quick look at geom jitter to see a little bit of variation. Probably, I mean, I suspect that everybody's also familiar with geom jitter.
Yeah. So, there's a little bit more here with the definition, but we can see where layer shows up again. And it, again, is has geom point hard coded. And then stat, the stat, again, is flexible. So, it's identity. And position is like kind of, yeah. And position is the jitteriness of, you know, the user of geom jitter is actually defined by this position. So, the last phase of what's going on as the data passes through this layer.
Let's look at one more, Isabella. Geom histogram. Let's look at the three main characters there. So, this is, yeah. Also, like a little involved. But the geom, you can, and so, the stat is bin. And the geom is bar. So, there's kind of like a major statistical transformation, actually, going on here, which is recording the account within a bin. And then the geom is bar. We see this geom also used in like geom bars. So, a geom that we know and is used elsewhere. It's the shape that is rendered on our plot. And then position stack, which is to help with the overplotting problem that we would have if we had like a group-wise histogram. So, we don't want those piled up on each other. Instead, we're going to have them stacked.
Yeah. I feel like every time I use geom histogram, it tells me, don't you want to change the size of your bin? You have that option, right? But it's great to have a default, too, right? At least, like, it's nice to have a default built in. Do you change your bin size? Yeah. If they go too skinny, I'll change it. Yes. I'm like, actually, I'm fine with a default. Thank you. But yes, I think that's the warning is like the right thing to do. Yeah.
Building a custom stat extension
So, today, what we're going to tackle is building our own stat. And so, this is the first, like, step in how the data flows through the layer. And so, this is actually probably the easiest way to do a geom or a layer extension. We're going to create a function that's user-facing called geom
means, which is just going to take the means of X and Y and put a point at that means. So, that's kind of our target. So, we'll do it. We'll plot, like, the penguin's data set and do a full on scatter plot, but then also be able to, with a single function, ask for the means to be plotted in the middle of that scatter plot, which, you know, it feels convenient to me. It's something that, like, I often want to do is, like, central tendency. And I think it's, you know, it's a good, like, this is a good starting point for us, kind of something that everybody understands plotting means.
And then we'll combine that with, yeah, we'll use a geom point and a position identity to construct this whole thing. Just for a little bit of context here, I'm going to hop in and say, Isabella, if you could switch to the page that actually is on the GitHub page that has the recipe for this for the means, just to show some context of what we're following behind the scenes would be great. I put that in Discord, and I also put an image of what we're going for here, which is that scatter plot with all of the black points, yep, and the red in the middle. That's what we're aiming for.
Yeah. So, rather than having to calculate this, you know, calculate the build, depth, millimeter, mean, and length, mean, and then plotting it, you know, can we build something that is just called geom means and let's just write that out, and then it automatically creates that dot? Yes. So, if you want to follow along, I put the link to that in the Discord and in the chat here, too.
Do you think in the interest so, my step zero, whenever I'm, like, tackling a layer extension, is to just, like, do the thing with base ggplot2. In the interest of time, Isabella, and just, like, keeping everybody's interest, maybe we should just copy that over from the recipes. I think, like, yeah, and then we can just kind of quickly talk through it. I think it will be, like, more interesting than, like, typing that bit out. Yeah, absolutely.
Okay. So, I think the pre-rhythm code is median, but I can change it to median. Oh, yeah. Yeah, we can. All right. So, just to quickly walk over what this is, I'm going to change the meanings, if that makes sense. So, first, we're going to create the ping of means, right, Gina, which summarizes the length and depth by calculating their means. Yeah.
So, we do, like, the computation outside of ggplot2. This is, like, one way to get that plot with base ggplot2, and then we have two point layers, but here we do use the data argument and then use our, like, pre-computed data set. Yeah, so, let's. Yeah, just to kind of show, like, this is what it would look like up to just using, like, a blank geom point, right, where it's just plotting the two scatter points, and then we can also add an additional scatter or geom point to add that additional layer, which is now that kind of calculate those means and give us that big red dot. Yeah. Yeah. So, we're going to, like, kind of refer to this as we build up our first layer extension.
Building the compute function
But and then so, that's, like, a step zero. So, something for reference that we all know as ggplot2 users. And then we're going to kind of reflect on the computation that needs to happen. And then we'll test that computation. So, we'll create a function compute group means. And yeah, Isabella's on it. So, yeah, we're going to have our data passing into this function, and then we're going to want to do some statistical transformation with it.
Um, inside of ggplot2, the data is going to refer to the variables based on the aesthetic mapping. So, the data, it's no longer understood as, like, the penguin data. It's just the generic data. So, we can do our statistical manipulation based on that. And then, yeah, summarize.
Um, x. We're going to do x. We're going to find the mean of x. And I'm sorry that everybody's I think there are some. Yeah. So, like, the we're going to go ahead and kind of be liberal with our means. We'll allow a mean to be computed even if there's an NA value. So, it's just a generalization of what we did up here. Yes.
And then one thing that you'll note is that with this computation, we want the scales to be operated on. We want all of the good stuff that happens for free in plotting to happen with our compute group means. So, an additional required argument in the function is scales. All right. Does this look good? Yeah. Great.
And then, so, we can then test our function with the penguin's data. But we're going to make the data first look like it's going to look when it's received by the layer function by changing the names of those variables. So, I like to do it with a select call. And x equals bill length. Sorry. Bill depth mm. And y equals bill depth or length mm. Yeah. And so, then having modified the data to look like it's going to look inside, right, because that's what kind of the AES call does within ggplot2 is now these variables have been declared to be your x and y. Then we can compute use compute group means as like another step. All right. Yeah.
Mm-hmm. And then, oh, we have those group means computed. So, this 17.2, we can see it reflected here. 43.9 here.
Defining the stat with ggproto
Yeah. And then, so, having that compute defined, we can go on and define a stat finally. So, we're like coming to ggproto, which is like the object oriented mechanism that works with inside ggplot2. Now we're in the internals of ggplot2. Now that we know that function works, we can define our stat using that function. So, that will be stat means. So, capital. So, this is using camel case. It's maybe something different than what you're using in like yeah. Stat means. And then, ggproto. Okay. Yeah. And then, we're defining a new class. So, let's go ahead and use the autocomplete. The underscore class. Yeah. And then, in quotation marks. So, we kind of have to write stat means twice.
Okay. And then, the nice thing with defining a new stat is that we can actually inherit a lot of information from existing stats. And we're going to inherit from the most generic one. So, we'll use inherit. It's also another one. I'm hitting tab and it's showing all of the different arguments that I can type in. Yeah. And then, not in quotations. We'll just refer to the object itself. Stat. Yeah. And then, we're going to overwrite some of the information that like stat would have in it. One of the slots is compute group.
Okay. So, this is no longer one of the yeah. Because yeah. So, ggproto is so general and there's a lot of different slots depending on what you're subclassing. Yeah. So, compute group, we're going to define as the function that we created. Yeah. So, exactly the function without parentheses. Are there multiple options for this compute group or is it something you define yourself? Yeah. So, it kind of depends on what you're after.
So, if you're interested in group-wise computation, then you would define compute group. There's also a slot for computing panel, right? So, if you only want the compute to happen when you're faceting out, then you'd go with like a compute panel.
So, here we like what we are saying is like, oh, if I change the color and use a factor variable, then I do like factor for species. Like, I want color equal species. Automatically, I'm going to have the group-wise computations done. Yeah. And then, like, this will actually work. But it's best practice to include one more helpful thing for your users, which is the required AES. So, you've probably seen like when you've missed a required AES, a message back to you saying, hey, you need to include a declaration about what is being mapped to X. So, our required AES here, what needs to come in for our data and to be declared is X and Y. So, we can enter that with the C function, concatenate, I guess it is, and X and Y.
So, you've probably seen like when you've missed a required AES, a message back to you saying, hey, you need to include a declaration about what is being mapped to X. So, our required AES here, what needs to come in for our data and to be declared is X and Y.
And that would be referring to whatever it is that we used in this function. Yes. Yeah. So, we are computing our means based on a variable that has been passed through. Does this look okay? Yeah. Let's execute that.
And then up here as environment. Yeah. Let's just, just as a matter of personal taste, let's just put each declaration on its own line. So, just a return for it. Just to have it like really clear that we have the four, these four kind of declarations. Yeah. And then we're like, so, we're at a place where we can actually test out stat means in our familiar function geom point. So, let's try that. We can, we're going to create something that's user facing, but let's test out our stat and actually create a plot.
So, that's going to be, if you want to like copy and paste code again, like maybe we'll copy and paste to the scatterplot. Isabella, if you want to do like up to here. Yeah. Let's copy and paste our scatterplot and then we'll do one more layer. Yeah. Yeah. And it's going to be geom point, but here we're going to like take advantage of the fact that we can change the stat. And we'll set it to equals our new stat means.
That it's sufficient. That's all I mean. Oh, and I think it showed up, but it's the same. Right. So, we haven't changed anything fundamental about geom point that's in play. So, let's just change like the, something about the set of statics. So, we can change the size to eight. All right. That's much clearer what's happening. Yeah. Yeah. Yeah. So, our stat is working as it should. And then,
Yeah, does anybody have, are there any questions? I feel like I've been like, or comments from our group? No, we did have a brief question that got answered in the Discord, actually, by Hassan
and James, which is amazing, about calculating based on stat summary instead. So Andrew had asked, instead of creating a separate geom medians and geom means, would it be possible to create something like geom summary and have the stat mean and median be defined when creating the plot? And Hassan said, yes, it is possible. And James actually linked to an implementation in ggplot2 as stat underscore summary. So that was really helpful.
Yeah, yeah. Yeah, so that is like, that's another quick way to do group-wise, group-wise, something like this in a group-wise way.
All right, well, for a time check, we're 35 minutes in, which means we're over the halfway point. And we have about 20 to 25 minutes left. And I know that we still wanted to do a little bit more, I think, on this and then also attempt an extension to plotnine. So I will leave it back at that. But if there are any more questions, let me know.
Yeah, yeah, I think maybe we'll look, I'm not sure how far we'll get with the plotnine stuff. I think we didn't really like actually rehearse that. But I think we can definitely take a look at what Hassan has available and some of the live chunks there.
I think one of the nice things is there are a lot of parallels, right? Yeah, yeah. Once we've walked through this, it'll look very similar if you're attending it in Python.
Real quick, do you mind if I show what happens if we don't fulfill this required AES? Yeah, great. So say we've defined here that we would need an X and a Y. So let's say what happens if I delete the Y? And I have definitely run into this error before where they're like, hey, you require the following missing aesthetics. And this error message is really nice, too, because it's very clear, hey, the one that you're missing is the Y. I think this is relatively recent, right? Like these really nice error messages from ggplot2.
Yeah, I think they're super helpful. And so taking advantage of making that declaration about what's required is very user friendly. Yeah, so we're almost at the point where we can create a user facing function, our geom means. And this is done really succinctly now with ggplot2 4.0.0, this latest big release with the make constructor function. So it used to be that you had to find some example scaffolding code to make sure that all of your arguments were in the right place. But Ton van der Brandt, who's done a lot of work on the latest release of ggplot2, has created this make constructor function for us. Let's have a look at how it works and what it's writing for us underneath.
Creating user-facing functions with make constructor
So Isabel, we can just do, yeah, we can do, you have the right version. I don't want to touch you for this. Thank you. We want to use it. It's very helpful. So yeah, we'll actually start, we can do, okay, we can do, yeah, so let's do the classic thing. Like if you're a very like classical extender, we can do, we can create stat means first. So if you're creating a stat, you might want to create a user facing function that is a stat. So this kind of, this is like no false advertising user facing function, right? So you're telling your user, oh, there's a stat called stat means. We're going to do a little bit of false advertising because users like to use geoms. They're comfortable with geoms and sometimes they never use stats. And as we saw with like geom jitter and geom histogram, there's a lot of false, useful false advertised user facing functions.
So, okay. So stat means we can do assignment and then make constructor. We go, yeah. And then we'll, as our, the first input, the X is going to be stat means. Yeah. And then comma, we have, we do have to specify two things, our geom equals geom point. In quotations or not? You can do, you can either do like refer directly to probably, sorry, it would be in quotations point, lowercase point. Yeah. Or you can do, or you could refer to the object itself, which would be uppercase geom, uppercase point. So this should work. Let's, let's try it. And then we'll see, we can look at the, what is the full written out function that make constructor has written for us. And we say, oh yeah, this looks like kind of familiar. It's this function that has our three main characters, geom point, position. The default is always to use that identity. And then within what's hard-coded is stat equals means.
Excellent. Yeah. Great. And let's just go ahead. We could use this right in place of line 44 and we'd get the same kind of result. We'd have to define the size, but we wouldn't have to do anything more in parentheses. Should we do that? Let's do it. Okay. Yeah. And now just stat means. Stat means. Oops. And then, yeah. It's there.
Yeah. And then let's do the like really friendly geom means with make constructor. It's really similar. Okay. And then our first argument is going to be geom point. Following the convention that if you have some user facing function, geom underscore, you'll have that hard-coded thing being, being the geom. And then we'll, we'll say, okay, it's a combination. Now we're combining a point and stat here. We have to say stat equals. Okay. And then we could use the object itself or means lowercase. Okay. Let's have a look at that. And we can look at the contents of the function. It is almost, it's an alias basically of stat means, but it has the different parts hard-coded.
Okay. So, geom, do you mean like geom? Yeah, geom point is hard-coded and the, yes. And the stat is flexible. It's like, you wouldn't expect people to like really use this function. It's, it's, you wouldn't expect them to go out and be changing the stat out. It would be like a weird move, but anyway, that's, that's according to convention.
So, okay. So, let's look at, we're like, we've, we're, we've succeeded, I hope, at getting to our goal. Let's do the same as 48 to 53, except for we're using that geom means. Yeah, we get the same. Yeah. It's the same plot. Yeah, it should be the same.
Are both of these steps required to get to geom means, creating stat means and geom means? No, if you're that, if you're the type of person that like just knows that you want that geom underscore function, you could go straight there and like your user are those type of people, then, then you can do that. It's just like the most classic thing to do, I think, and like, and I feel like it's appropriate to, to talk about is, is creating a stat user facing function when you create a stat object. I feel like the rest of the folks on the call would, would probably agree. Yeah, that's very interesting. I don't think I've ever used a stat function in ggplot2 before, and maybe because they've all been masked as a geom one.
Geom vs. stat: understanding the difference
Yes, I think that that makes sense to me, too. And Nathan Jeffrey had just asked in the chat about the difference one more time between a geom underscore something and a stat underscore something. Yeah, so they're both layers. And this is like, even something that Hadley talks about, he's like, oh, I should have just called everything layer underscore histogram layer underscore point layer underscore jitter. Because they're used like almost in the exact same way.
The the main difference is like what is modifiable by the user. So what's the arguments that are hard coded in the in the stat underscore case, it's going to be the stat that you can't change. And in the geom underscore case, it's going to be the geom that is that is not changeable. So it's for more sophisticated, if you have more sophisticated users in mind, and like maybe you're going to become a more sophisticated user yourself, providing stat means means that you can mix and match like the geoms that that goes in the this stat means function. So that's like one argument to create both.
Hassan, do you have any insights into this problem? Yes, the way the way I think about it is, or the way it is, is that a layer is exactly as, as a layer is would say, every like the drawing programs that you use, if I use Photoshop, you draw on a layer. Now, because a layer has so much functionality, they created like a geom for like, basically to wrap layers into, like, more user friendly things. But when you are creating a visualization, before you create the thing that is observable, that like the geometry, you have to summarize the world. So you have to do a computation. And that computation is the is the statistic. So there comes in like, this like idea of a statistic, but you cannot have a statistic by itself, without like, it's meaningless without being accompanied by a geometry that you can see if you're doing a visualization. So a statistic also becomes a convenient way to create a layer.
So you end up with this, like with these two battling ideas of like a geometry, like fitting a layer with a geom or creating a layer with a statistic. Now, where a statistic makes sense to make more sense is when things get a little more complicated. And, and you are actually thinking in terms of the statistic first, and then the geom second. For example, like, when you do like, when you think about the densities, like, yeah, you tend to think sometimes you tend to think a little more in terms of like, the statistic or what type of like parameters go into this density, what type of it then, obviously, you get to visualize it as like, as a curve and, and like, so many other things can do that. So you so when you look for that, when you do a search, where like the places where most stats are used, you'll find them being used, for example, like stat smooth, because you wonder about like, oh, what statistic is being deployed to create like this smoothing thing, usually some kind of like a density estimate, and then also, like, stat density, like, almost like almost the same thing.
So, so these are kind of like a conflict between how to think about how you get that, like, last, like the output that you care about. And that tends to, to drive the choice between geom and statistic. But in all honesty, you, like, you probably could have defined everything the same, and it would take and have taken away that, that friction of like, oh, which one, like, which one should I use, which one, but in most cases, like geom is wrap, wrap whatever you want in a, in a geom. And yeah, it's a, it's a good rule of thumb.
But in all honesty, you, like, you probably could have defined everything the same, and it would take and have taken away that, that friction of like, oh, which one, like, which one should I use, which one, but in most cases, like geom is wrap, wrap whatever you want in a, in a geom. And yeah, it's a, it's a good rule of thumb.
Thank you. That was really helpful.
How about we add, let's just do one more aesthetic mapping here, to show that for free, we're going to have group wise means computed. And so is within geom means? Um, we could, you can just, let's use the weird plus AES. Oh, okay. Color equals species. Cool.
And then species is a character or a factor variable. And so that's going to trigger for something, a stat that's compute group, it's going to trigger group wise compute. So each one of these is reflecting the mean for each of the species. So this is chinstrap
Yeah. So I think like, that's one of the things that I'm really drawn to about extension is like, oh, you've got all this for free. We could do that facet wise too. We could go like facet island, but since like we are, um, are running out. Yeah. Let's do it. Let's do it.
That's it. Rat maybe. I feel like most correct thing to do is facets equals vars and, uh, island.
Not, I think that in plotnine, you probably have to put quotation marks, but not in ggplot2. Let's, let's, let's give it a go.
Yeah. So, um, so like computing all five, um, group wise means based on X and Y, um, all for free. Yeah.
They're like kind of recap too. So it means like rather than having to compute this for each one of these different combinations of, um, of species and of islands, and then like calculating all that and then putting it in some separate geom point. Like all we have to do is create this geo means once, and then we get everything else.
Yeah. Yeah. Um, and like, if you're like kind of doing some storytelling with data, you might like break this plot up and save a plot object and then like add the facets like, oh, we we're doing this by species and, and we can break this up further. And it can, like code can be like super concise.
like code can be like super concise.
Overview of recipes and Python parallel
Um, so maybe we can, um, just look at that, like other recipes to expose, like really quick to, um, like the compute panels and then let's look at Hassan's. So, so we have this resource available. Um, and so we went through the first recipe, basically it talks through a lot of concepts and then at the end there's live code in chunks where you could like do this exercise again. Recipe two, um, it looks at, um, like using geom text on how you might use, um, how you might combine it with a stat. The third recipe is like a bit of exposure to panel-wise computation. So if, if you're interested in that situation, um, and, and the fourth is more about like, I don't know, like using this in stats classroom context. It's thinking about, um, yeah, linear modeling, but like with, uh, where the, the, the model is, um, is, uh, computed in a unified way. So, um, but let's, and then maybe we could, Hassan, do you want to talk through, um, your work a little bit? Uh, the easy recipes, I feel like that maybe is what we have time for. Yeah. And it looks very similar, but if you notice this support, yeah, this site is, uh, all in Python. Yeah. Um, it's, uh, it's essentially a parallel between what you're doing in, uh, um, the easy geom recipes, the original in R, and then how does that translate to, to plotnine? So the only difference, the big difference and encumbrance that you would find, it's mostly that it uses pandas. So the data manipulation, um, that is not as, is not as fluid. Um, it doesn't look, it doesn't look as clean and as, as aesthetic, but on the other hand, um, the, uh, difference, yeah, it's like, it's a little clunky, unfortunately. Um, on the other hand, um, when you are creating the, uh, the geoms and classes, you don't have to bother, uh, with the, and stats, you, you create them once you don't bother about like the wrapping of like, oh, you have this object, let me drop it into a function.
So, and, uh, the rest is, uh, the rest is, uh, written with them. So, um, like the steps are the same. Yes. This, this, yeah, the steps, the steps are the same and, uh, um, and yeah, the live examples work as well.
Oh, that's right. Pyodide for Python.
Other types of ggplot2 extensions
Amazing. I realized, Gina, um, I skipped over this part in the beginning. I'm sorry that there are actually different kinds of extensions too. So these that we've been talking about are the layer extensions. Um, but there are multiple other ones, right? I think I have.
Yeah. So I think like, um, what's also popular. Oh yeah. You're the theme extensions. Does this theme park like advertise a lot of, uh, different theme packages or just offers like, oh, okay. I don't really know it.
I remember being Barbie when Barbie was out. It was very, very popular.
Yeah. So, and the theme extension is, I think it's especially fun to get into now because, um, even the, like, um, the layers, like the geoms are responsive to theme. So, um, so that's like an innovation in, um, I think it, I think it's ggplot2 4.0.0, um, where, where, um, like the, the points themselves used to not be like as, or like as responsive to, uh, theme declarations, but now they are with, um, the inputs like, um, paper and ink, like point kind of shows up in ink color. And, um, and, and that's really fun. It's like a way to overhaul the look and feel of your plot. Um, and in a really easy way. Um, yeah. Yeah.
Are there other questions that.
I think that we are just all wandering at many themes that we can go try. I put an example of, of Barbie's theme in there. Tom is looking at the Wes Anderson themes. Yes. They're super fun. The Simpsons one is also really, really fun. Um, I also shared in the discord, a link to, um, uh, older blog posts that I wrote for getting started with geom text path, which kind of shows how to create some basic stuff, which is great. It's my favorite extension package for sure. Um, and we also had some shout outs to tiny plots for some great implementations of some of the things that we're talking about today. Thank you. No tobacco for the shout outs there. It's a ggplot2 rapper. You can go play around with all of those. Um, okay. No tobacco says how's there's no, how is there no Barbenheimer theme? Go make one, go make one. That's a combination of Oppenheimer and Barbie. And there's so many other things like there's themes, there's layers, and we also have this one, but this is a different kind of extension, right? This is scales. If anybody has seen in this poison frogs, love it. Absolutely love it. And skills can encompass so much, right? Um, because skills could encompass formatting for text inside of, um, inside of different parts of your plot. There's all kinds of places that text could be in your plot, but this scale is for color scales, which is really exciting. Palettes are so much fun. Um, and I know that we've reached the top of our hour. We have three minutes left, so we have to say thank you so much to Gina. Thank you to Hassan. Thank you to James. Thank you to everybody who answered questions. Gina, thank you so much for being here and Hassan. Thank you. I hope you had a good time. Thanks so much for having us.
Yay. Everybody, please go forth. Use your imagination on what you could use this knowledge to build. These are very, very user-friendly entry points, those recipes, right? But from that, so much can come, and you've seen through the other extension packages just how much can happen. We enjoyed having you. Thank you for hanging out with us. We'll see you next week. Bye, everybody.
