 Hey folks, in the last several episodes, I've been stepping through the development of an animated climate spiral diagram trying to recreate the figure that Ed Hawkins created a number of years ago. That climate spiral was just amazingly popular on social media, I think it got picked up and was shown at the Olympics and in other different venues. Well, fast forward to the last couple of months, the folks at GISS at NASA, the place that we're getting her data from, they released their own version of the climate spiral. What I would like to do in today's episode is to help you think through the logic of how we can go from the Ed Hawkins' version to the NASA version. And so what I want to do is take a little bit of time to step through these two different animations and to think about what are the differences that we can see. I think I've got maybe a half dozen different differences, and then we'll work through those to get our current version from Ed Hawkins' version looking like the NASA version. So the first thing I notice is that my much-beloved background gray with the black field for the plotting window is gone in the NASA version. It is all black, and there is no title. So that's the first thing, thinking about the basic styling. The next thing I notice is that the month labels in the NASA version are all parallel to the x-axis. They're all horizontal, right? They're not tangential like they were in the Ed Hawkins' version. Also, I notice that January is at the 12 o'clock position, not at the 1 o'clock position in the NASA version. Also, I notice that the labels for the months are in all caps, and they have a yellow color to them. Also, I notice that they're on top of the data. They're not behind the data, okay? And so they're a little bit closer to the data than what we saw with Ed Hawkins' version. Next, I notice that the color scheme is a bit different. So in the Ed Hawkins' version, the color is by year, going from 1880 all the way up to 2022. As you go through time, we went through this geomeridus or color veridus color gradient. In the NASA version, on the other hand, it goes from blue to red, and it goes through white in the middle. And instead of incrementing that by year, it's incrementing it by the temperature difference. The other thing with that that I notice is that the year label in the center of the diagram isn't white for the entire animation. It's actually changing color to reflect the temperature. The next thing I notice is that the grid line that we put in in Ed Hawkins' version, we have these red concentric circles for one and one and a half degree difference. They are now yellow for minus one and plus one. And there's a green line for the zero temperature difference. Also, these lines are on top of the spiral. So they're not being obscured by the lines being traced on top of them. Finally, one thing I notice is that the spiral itself, the line seems a bit thicker than what we've been working with. It also seems to have a little bit of a texture on it to make it look more like a rope. So it has a little bit of 3D dimensionality to it. I don't know that I can do anything about that. The other thing I notice that's really cool is that in the NASA version, when you look at the end of the line, even if it's in a region that's red, the end of the line is white. And as you allow it to move forward, that line turns red. So there's a bit of a transition in the color of the line. Again, I don't think I can do anything about the texture or this gradient coloring that's got an animated effect itself. But it's interesting to think about. And I think that's pretty cool. And it overall gives it a pretty cool feel to the visual. So my plan is to step through these different elements. And as we step through each element, what I want you to do is to think about where in the code would I make these changes? Okay. And so if you want to get the code that I am working with, please, please, please go down below in the description. You'll find a link to a blog post that'll take you to GitHub. And then you can get the data and you can look through it with me in real time. And you can say, huh, I think we're going to remove the titles. And so this is where I would look to remove that title, right? So I want you to make some hypotheses, so to speak, about what you would change and where. And I'm going to be doing the same thing as we go through this video. I'm here in our studio. And again, I'm starting with my climate spiral NASA dot r script. It's the same script that we ended with at the last episode. I've copied it over and changed the name. Normally, if I was working on a project, I would probably be working in the same script and using version control to keep track of different versions. But I think people would like to have the project at the very end, so they can see all the files and all the figures next to each other. So I'm copying even though this isn't exactly how I would do it in the real world. So one thing I'm going to do is I'm going to come back down to the bottom of my code. And for now, I'm going to go ahead and turn off the animations. I'll also get rid of the transition so that we're working with a static version of the image. And I will save this with gg save kind of the dimensions that I'm going to be working in. And I'll call this figures. And I'll call it climate spiral NASA dot png. This needs to be in quotes, because that's the name of the file, of course. And then I'm going to grab these widths and heights and units and probably the resolution or not. And so again, this is what I'm going to use to keep track of a static version of the figure rendering these gifts just takes a very long time. And so I'm going to make everything as a static image. And in the end, we'll make sure it works as a gift. So with all this, I'm going to go ahead and load it and generate that figure. And I noticed I got an error message about res. And what I really meant was DPI. So I'll go ahead and do DPI. So again, this is the final screen grab from the climate spiral that I made to match Ed Hawkins is. And so the first thing I want to do is to make the whole visual black. And so again, think to yourself, where might we want to change everything to make everything black? Well, if you said the theme function, you're right. And so up here in the theme function, we have panel background and plot background. And we currently have it set to this gray, I'm going to put in black in place of the fill and the color. I don't know why I have that size. So I'll go ahead and remove that. One thing also to keep in mind is that I put in a object to have the background be a circle black with a gray background, right? And so I had done that way up here in my geome rect. So I'm going to go ahead and comment this out. The other thing that I had done was that I had a label for my text to flash up the year, right? And so I had this label padding of unit 50. I'm going to go ahead and remove that padding because we made the big padding because when I took the geome rect and put into polar coordinates, I made a donut, right? And so by making the padding bigger, we could plug the whole of that donut. Well, if everything's black now, I don't need to really worry about that. But I still want to leave that fill equals black, because this is going to be on a black background. And so if I remove that, then I would have a white fill and I'd have this white thing with white text. And that's not what I want, right? Alternatively, we could go back to geome text, but geome text doesn't give you a solid background. And so what you would then see would be the labels or the numbers writing on top of each other. And it just looked like a big jumbled mess. So let's run this and see what we get. So we now have that black background, we can't really see the difference from the geome label. But we know it's there, right? Good. So the next thing I want to do is get rid of that title. And so where do you think we're going to get rid of the title? If you said the labs function, you're right. So let's come back up here. And we're going to again, look here in the labs function, and see that we have title equals all that. So I'm going to replace that with null. The other thing that we could do would be to say plot dot title, right in here, right? And so we could replace this with element blank. To go ahead and get rid of that, we could actually leave the title in the labs function and say plot title equals element blank. And that would get rid of it for us. We could actually do the same thing for axis title. So even though we don't have any axes, we could say element blank there as well. And we don't have to worry about anything showing up. And then we could get rid of axis title y here, because that's redundant. So now we've gotten rid of the title, we have that black background. What we now want to do is work on the styling of our different months. And so the first thing I want to do is to make our months horizontal. And so where do you think we'll do that? Well, yeah, I mentioned we have a geome text or a geom label, where we are plotting the months. And so you can see here that we have a data frame called months labels. And so that tells me this is where we're making that modification. We also have this angle argument. And what I'll do is go ahead and comment out the angle, remove that comma at the end. And let's see what it looks like when we just do that. So that gives us our months being horizontal. I noticed the September and March are getting trimmed a little bit. I'm going to hold off on worrying about that for just a minute, just because we're going to be fiddling around with the inner dimensions. And so I don't want to worry about the positioning of the months until I've got everything else sorted. So the next thing I want to do is make those months all caps. And I want to make them yellow. And so we'll come back up here. And so we again use that data month labels. And so I'm going to come back up to month labels here. So I'll take this month dot ABB vector, which is ours built in vector with those three character abbreviations for each month. And I can use it as the argument to two upper. So if I do two upper on month ABB, then we're going to get all caps for our 12 months. I'll go ahead and load month labels. And then that will get propagated down into here, right? And so I currently have the color as white. Let's make it yellow. Our month labels are now all uppercase and yellow. The next thing I want to change about the labels is the NASA version starts with January at 12 o'clock and December at 11 o'clock. And so if you recall, when we were talking about cord polar, there's a special argument that we were able to give cord polar to get things shifted by that, you know, five minutes effectively. And that's back up here in cord polar we have start equals two pi divided by 12, right? And so that's basically five minutes on a clock face. And so the start argument takes a value in radians to tilt or adjust the coordinates. And so I'm going to go ahead and turn that to zero. We see that January is now at 12 o'clock, as we expected from removing that start argument from cord polar. Of course, our lines to indicate kind of the grid lines of the different temperatures is a little bit out of whack. We'll worry about that here in a few moments. But one thing I want to do before we move on from modifying those month labels is I want them to be on top of the data. And so we can do that by running the GM label after the GM text rather after our GM line. And so if we come back up here to where we're modifying this GM text, and again, I want it to be GM text rather than GM label, because GM label has a background, whereas GM text has no background, right? And so if I if I made this GM label, then when a line went behind it, we wouldn't see the line. So I still want to be able to see the line. And so that's why I'm going to use GM text. And because I want the text the month to be on top of the line, it needs to go after. This is also a point for why I want to modify it using GM text rather than scale X continuous like I have here. And that's because scale X continuous would move things back. And while I could perhaps move in the scale the months, it's just going to get a lot funkier. And I already have all these great tools. So I'm not going to worry about that. I think I can also probably comment out for later removal, the scale X continuous. And so we don't really see much of a difference. And I wouldn't have expected to at this point anyway. The next thing I want to take on is our color scheme. So the color scheme uses a Veritas gradient. And so it's a continuous gradient. And it's being incremented by time, right? And so the more yellow, the more recent, the more purple darker color is further back in history. And so I want to change that instead of being indexed or incremented by time by year, I want it to be incremented by the temperature difference. I also want the number in the middle of the figure to be changed by the temperature difference as well, instead of staying white. So let's worry about the spiral first. So what are we going to change to get the color to represent the temperature difference rather than the year? Okay, you have an idea? We're going to go into ggplot back up at the beginning of this pipeline. And what you'll notice is that we have color being by year. Let's change that to be T diff instead. So let's run this and see what it looks like even though it'll still have the Veritas package color scheme. And so what we can kind of see is that there are bands more by temperature, which is kind of the position on the radius rather than by time. I notice a little bit of pixelation in the lines. And that's probably because we're trying to assign a line segment to be a single color. And it's maybe not so happy about that. Anyway, let's now change our color scheme. And we can do that in what function? Well, we're probably looking for something that starts like scale color, right? So if we come up here, we see scale color Veritas, we want scale color gradient two. So remember, a scale color gradient goes from like one number to another number or one color to another color scale color gradient two goes from a minimum number to a middle number to a higher number. And so we'll then replace this, the argument will be low. And so that will be the color will make that red, high will be blue, and then mid will be white. And I believe that is the and that's the default. The other thing we want to add is midpoint to be zero. So that white occurs at zero. And I clearly messed up because I have the lower temperatures being red and the higher temperatures being blue, I meant to switch that. So we'll come back up here. And this will be blue, and the high will be red. The next thing I want to modify is the year to be the same color. And so again, we can come back to GM text. And we've currently got the GM label here, right? And so that's where we're modifying the label by year. But we are replacing the AES the aesthetic from way back up in GG plot with color equals white. So if we go ahead and remove that, then our color should be set by the AES way back up here in GG plot, right? To be color equals t depth. So let's try this. And so now we see our year 2022 is the same red as right over here. And when we animate it, we'll just have to double check that the year is the same color as the line around it. Now we want to take on the grid line around the plot. And so again, where did we change that? Well, we created that in GM H line. And so we had intercept at one and a half and two. And so we want intercepts at one, zero, and negative one. And then our color, let's make it yellow for now. And so we can kind of see those yellow lines, but they're behind our spiral, right? So let's go ahead and bring them to the front. And so that means running GM H line after GM line. We also want those labels for the the temperatures to be on top of those lines as well. And so we'll go ahead and grab that GM label there and put it after our GM H line. So it sits on top of that. And our color here is red, but let's make that yellow. And again, that was with the temp lines. And so if we come back up to temp lines, our exposition should be one. So it's at the top. That's January. And then our Y should be, as we saw, one, zero, and negative one. And then our temperature should be, I think it was plus one degree C minus one degree C. And then in the middle was zero degrees C. So that's backslash you zero zero B zero C. And I'm missing a comma here. So that doesn't look great. What I'm noticing is that we have a GM label with a black background. And that black background allowed us to interrupt the segment going or the grid line going around the plot. I think what I want to do instead of GM H line is to use a GM segment instead and turn off that black background on and actually maybe just get it to be GM text. And so where I had GM label, let's go ahead and make this GM text. And we then want the fill and label size to go away because those are not attributes or arguments for GM text. And so again, now we see our temperature on top of the lines. And I think if we use a GM segment instead of H line, then we can set the start and end position. And we'll effectively get that break in the line anyway. Because if I I can't make the back, I mean, the background of this is transparent, right? That's what I'm seeing. But I can't make it like opaque for the for the grid line, but transparent for the rest of the data, right? So let's see if we can use GM segment instead. So we'll come back up here to where we had GM H line, GM segment. And I'm going to make a new data frame for my grid lines, right? And so we'll call these grid lines. And it'll be a tidal. And we'll have an x being three values, an x and being three values, a y being three values, and then y and being three values. And I'm going to grab those three values from these intercepts, right? And that's going to be the y. And the y end is actually going to be the same as y. So that and then my x, I'm going to be again, January is one. And so if we start at maybe one and a half, for all the x values, and then for the x end, we want it to end at maybe 12 and a half, right? And so now down in GM segment, we're going to give data be the grid lines. And then our AES will have x equals x, y equals y, x and equals x and you get the idea. Y and color yellow. And then we'll do inherit AES equals false. So I think that strategy will work. Obviously, these settings aren't quite right. So something I want to do before we move on though, is to set those lines to be yellow, green and yellow. And so we can do that here with the color aesthetic. So we'll do yellow for plus one, green for zero, and yellow for the negative one. And I'm going to copy this line down actually for also the text label. Very good. We now have our two colored lines. And again, like I said, once we move things around, we'll fiddle some more. So we're going to now change the limits. Previously, we went from negative two to 2.7. We don't need that. We also don't need the secondary access, right? So I'll go ahead and get rid of that. And so our limits, let's have it go from minus 1.5 to 1.5. I don't think we need these breaks. And let's see what this looks like. So I'm getting a warning message that removed 12 rows from geome text. And sure enough, those are my 12 months. So coming back again, our limits were from negative 1.5 to 1.5. Let's go ahead then and put our text for those months. Let's put that at 1.5. So now we're like really zoomed in. I think we want to turn off that expand. So let's go ahead and do that. So it looks better. I think I'm going to come back and maybe put back in the expand. So let's make that maybe negative 0.3. And I'm going to decrease the lower limit to 2.0. So I think that scale looks pretty good. We need to bring down the year a little bit. So let's bring it down to maybe negative 1.7. And I think that looks pretty well centered. Now I want to turn our attention to the gaps. I think these numbers need to be a little bit smaller. They're currently the same size as the month. If I look at the original, the temperatures are quite a bit smaller than the month. So this is the geome label for the temperature. And this is for the month. And again, they're being set to the same size. I always forget the size of these things. So that's on the temperature lines. Let's do size equals 3. See what that looks like. So it could probably go down a little bit. One other thing I noticed, the little thing, there's a space between the degree and the C. So let's maybe reduce that 3 down to 2. And then for our temp lines, we could go ahead and put it in a space between the Unicode and the C. So I think that looks pretty good. It wouldn't be nice to have that text be bolded for those temperatures. So I promise I'll stop messing with this here. But let's come up here to geome text. And we can do font face equals bold. And I think that looks better. So now what we want to do is modify the start and end position of our segments, right? And so for that, the inner circle, I think it looks pretty good. Maybe we could just open it up a little bit of a smidge. So again, we can do that back up here in our grid lines. And so we're going to give three values for x and xn. And so we had been doing one and a half, one and a half, and one and a half. And then same here for xn was 12 and a half, 12 and a half and 12 and a half. And so now we want to modify these things. And so I want to open it up a little bit. So let's do 1.6 and 12.4 for the the inner circle for the out of the middle circle, we can bring it in a bit more actually. And so instead of 1.5, let's make that 1.3 and 12.7. And then we can bring it in more for the outer circle, right? And so let's do like 1.1 and 12.9. Again, we're just gonna have to try and try on there. So I think we did a pretty good job for the inner circle in the middle circle, the outer circle needs to be opened up just a smidge. I think that's pretty good. So again, for that, we'll do let's do 1.2 and 12.8. I think that looks pretty nice. This is what the original looked like, right? I can see that theirs is quite a bit smoother than ours. That just kind of annoys me a bit. But in general, you know, I think we're doing pretty well. You know, the colors are a little bit different. But you know, you could go and play with that on your own. I think in general, again, we are using the same data here, the data from the other visualization that we started with that that original visualization that we're trying to mimic was a different data set than what we've got here. And so, you know, there's a little bit of this striation. So I'm not totally thrilled about that. That's something that I might go back and play with later. But I think that looks pretty good. So let's now turn this into an animation. So to do that, we can turn back on our transition manual. Let's go ahead and uncomment this and get rid of that extra comma. And I'm going to go ahead and add climate spiral underscore NASA dot gif. So I think this looks pretty good. I'm pretty happy with the way this turned out. There's a couple of limitations that I think we have because of our tooling in R that because I can't help myself, I'm probably going to dig into a little bit more so that I can figure this out. I hope you can kind of see my logic in working through the challenge of taking existing code and modifying it to look like something else. Let me know down below in the comments which version you prefer, NASA or Ed Hawkins's version. Also, if you have ideas for how to solve these problems that I've run into, let me know down below in the comments too and I'll try to highlight those in a future episode. All right, keep practicing with all this. We will keep marching on, looking at different ways of visualizing these data and please tell your friends what we're doing here and I'll see you next time for another episode of Code Club.