 Hey folks, welcome back for another episode of Code Club. I think this is the last video in this series of videos about a dozen or so where I have been building this data visualization showing the level of droughtiness around the world. You'll see that each region is a one degree by one degree latitude-longitude region that is indicated by a pixel that is a different color and the color is scaled according to a z score. And what that means is that it's basically looking at where is the total amount of precipitation for the past month relative to that same window of time over at least the past 50 years. And so where I am is right about here in the upper Midwest of the United States. It's been very dry over the last couple of months. Certainly the parts of the western United States are also dry and parts of Europe are pretty dry as well. And I've noticed as I've been developing this that Australia has been getting greener. So I think they've been getting more precipitation than normal over the past month or so as I've been building out this video series. Anyway, one of the things that kind of bugs me about this visual is that because we don't have data for all latitude-longitude combinations on land mass, we have a lot of open spaces here in the visual where it's not immediately clear where we are in the map, right? So if I were to come like right here, I think this is England, but I'm not totally sure, right? I think this is New Zealand, but I'm not totally sure. I can pretty well decipher the boundaries on the United States, but everything else is a little bit of a guess. So what I'd like to try is to overlay or rather underlay the plot that I currently have with the actual boundaries of the different countries in the world. And to do that, we will make use of a special geome called GeomeMap. Heading over to Visual Studio Code, I've got my plot drought by region.R script that lives in my code directory. If you want to get a copy of the code and everything that goes into making this project, go down below in the description. There's a link to a blog post for today's episode that'll show you everything you need to get caught up. I also have a video tutorial on how to use all that information to get to where I am in the development of this project. I'm doing this in Visual Studio Code, as you can see, rather than RStudio, I'm doing that because I want to get more acclimated to using Visual Studio Code. Also, I'm using tools from Bash, I'm using Kanda, Mamba, Snakemake, all sorts of other stuff that are perhaps just a little bit beyond what I really feel comfortable doing with RStudio. I mean, you could certainly do this in RStudio, but like I said, I really do want to get a little bit more comfortable with using VS Code. So that's what I'm doing. If you want to learn something, you got to use it. So I'll fire up a terminal here. And I'm going to get into my Kanda environment. I'll do that by doing Kanda, activate drought. And now I'll go ahead and start R. And I'm going to go ahead and run these various commands so that I can see where we are with the code and the data that we have. The data that I have on my local computer is a little bit dated from what we have up on the website, but it'll get us pretty close to what we want things to look like by the time GitHub actions reruns everything with the new data. So this looks a lot like what we have up on the website right now. Again, what I want to do is add a thin gray outline to this visual to indicate where the country boundaries are. To do that, I'm going to make a blank map that I will later fold back into that visual that I already had for the level of droughtiness. I'm going to use a function from ggplot2 called map underscore data. And then I'll say world. And so then it says package maps is required for map data. Would you like to install it? I'm actually going to say no, because what I want to do is make sure that it is part of my Kanda environment. And so if I come back here, and I go to environment.yml, I'm going to go ahead and add our hyphen r hyphen maps. And I want to double check that that Kanda environment actually exists. So I'll do Kanda heart hyphen maps. And it looks like it does exist. And that is part of the r package. I wonder if it's elsewhere. If it's part of Kanda forge. So we'll check that out. So Kanda forge has it as well. Great. So that's using 3.4.1. So I can do our maps. 3.4.1. Let's do 3.4. And not worry about the point one. So we'll go ahead and save that. I'm going to quit out of our so I want to double check the environment I'm in. So I'll do Kanda ENV list. I'm in my drought. And then I'll do mamba ENV update hyphen hyphen file. And then environment.yml. Wonderful. So I see it did install 3.4.1. We're in good shape. And again, we are in that drought environment. But just a double check will do Kanda ENV list. Yep, drought. So now I can go back into our and let's go ahead into my drought, plot drought by year. I'll go ahead and reload these different libraries. We definitely need the tidy verse library to build out this demo of a plot. So if I do map data world, that should work now. And what I get now is a gigantic data frame that has all sorts of stuff in here, basically boundaries latitude longitude boundaries of of this full data set. So if I do ahead on this, I see launch lat group order for Aruba, right. And so again, this is the data that you would use to basically draw the boundary of different countries. Alright, I'm going to go ahead and call this world map, and load that as a data frame. And then I can do ggplot. And then my data is going to be world map, right. And then AES, I'll do x equals long y equals lat. And then I'm going to add a special aesthetic, which will be map underscore ID equals region. And again, that's going to be this region column, which is the name of the country. This map data function allows you to get all sorts of different maps. You can get the United States, you can get France, I think you can get Great Britain, we're getting the world. So that should be great. Then we can add to this by doing geome underscore map. And then we need to give it a map, right, which I will then say is map equals world map. And this shows us a world map in very nice detail. It's a filled with black with white or gray boundaries on it, which is pretty cool. The other thing that will note is that the aspect ratio isn't preserved. So if I pull in, I can make it wide or short. So we'd really like to do would be to use chord fixed. And so now we see that we have the correct aspect ratio of one degree longitude, equaling one degree latitude on the y axis. So what I'd like to do is maybe clean this up, as it is to make it look like we'd like it to be underneath the plot that we already have. And so to do that, I would like my fill color to be transparent, and I want my boundaries to be gray, and I would like the backgrounds to be black, okay. So to see how we could do that, let's go ahead in here. And to make it transparent, we could do fill equals na. And so we can see that the fill is gone. I think the boundaries on those countries is the same gray as the background. So why don't we for now go ahead and do theme. And I'll do panel dot background, elements, rect, fill equals black. And then we'll also do plot dot background, equaling element rect with fill equals black. So I'm still not seeing it. And I think maybe I need to set the color. So I do color equals white. There we go. Now we have the boundaries on those colors. I think the default color was set to na. So the default color of the boundaries was transparent. So I basically flipped things and made the color, which is again the color of the boundaries to be white, and the fill to be transparent. I don't need those grid lines. But I think we're in pretty good shape. The way this currently stands to move forward. One thing I'd like to do is go ahead and get rid of Antarctica, because I don't have any data for Antarctica. And so let's see how we might go ahead and modify this to get rid of the Antarctic data. So again, up here in world map, if I look at the head on that, so if I do world map head, again, the region we see is Aruba, maybe we could do a count on region. I mean, I don't really need the count. I mainly want the names of the different regions that are in there. And I'm looking for something that's like Antarctica. So maybe I'll go all the way back up to the top here. And get in there. It's a lot there, right? And we see Antarctica, very cool. So what I'm going to do is I'm going to remove Antarctica. And I can do that with a filter region not equal to Antarctica, right? So now we create a world map green plot the data. And we now see Antarctica is gone from the bottom of the plot. And that's pretty cool. One thing I might think about doing is that the data that I have up in the heat map is on that one degree by one degree grid. And so that's why everything looks kind of pixelated, right? So what I might do is make the map pixelated as well. And so to do that, I could go ahead and do a mutate on my lat and then do say like round on lat, and then long to be round on long to again update that world map variable and regenerate the plot. And so now we see a fairly pixelated view of this map as well. Let's see, I'm not sure if I'm like this or not. So maybe we'll come back to this in a bit. Now what I want to do is put this behind the heat map that I already have. So I'm going to go ahead and take this world map data, as well as the gg plot code and come back up here above my plot. Alright, and so I've got world map defined. And I think what I could do would be to mainly go ahead and add all this stuff to a geo map, and then add geo map into my gg plot code, right? So here I could do geo map, right? And let's see what do we need. So we would want to go ahead and add all this stuff. I don't need to run gg plot again, I can pop that into here. I could then also do map equals world map. And I want to plus at the end of this line. And let me double check if there's anything else that I wanted. Oh, I also want the colors, right? And so I want my fill to be na and my color to be white. And so again, I come down here. And I can add that. Cool. And yeah, so I don't think I need any of this because I've already made cord fixed down further here right there. And I also made the background black and got rid of the grid line. So I can go ahead and remove this. And let's see what happens. Oh, I forgot to run everything else in my code. So let's go ahead and load everything else. Very cool. We now have our heat map data on top of our map map data, right? I noticed that the line thickness is maybe a little thicker than what I'd like. But I also noticed that I got a warning message of ignoring unknown aesthetics x and y. And that's because I goofed. Geo map doesn't actually have the x and y aesthetics. So I'll do X, a question mark Geo map. And if I scroll down a bit to the aesthetics. Yeah, the only one that's in there that's required is map ID, which is what I have for region. There's nothing in here for x and y. So let's come back up to our code. And the way that we can be sure to include the correct x and y coordinates is by using the expand limits function. So I'll go ahead and remove x and y from here. And then I'll do expand underscore limits. And then my x, the x limits is going to be from world underscore map, and then dollar sign to get the column for the longitude. And then y world map dollar sign lat for the latitude. And I think I'll also add to my Geo map here inherit dot AES equals false. So that we're not worried about it grabbing AES values from up here in gg plot because I've set those pretty specifically with map ID equals region. So that ran without any warning messages. And we now see our map looks good. Of course, we now need to do some tweaking to make those lines a little bit thinner. And to make that thinner, we can come back up here to Geo map. And I think what I'll do will be size equals let's do 0.2. We'll start there and we'll adjust. So that looks thinner. Let's maybe go down to 0.1 to make it even thinner still. Again, that was up here in Geo map. I think that's a good thickness. It still seems a bit too pronounced. I might want to go ahead and make the color a gray, maybe the same gray as my font. Let's try that out. So that's that hash f five f five f five. So yeah, let's try that instead of white. So I feel like that's a little bit more subtle and good. I'm not such a fan of this pixelated line. I think I'd rather have the true shape of the continents and countries. So let's come back up here to where we defined world map. And I'm going to go ahead for now. And I'll comment out that mutate. So I like the shape of the countries a lot better this way without that pixelation without rounding it by latitude and longitude. I still feel like those lines are maybe a little bit too thick. So let's try to make it even thinner still. As you've seen in past episodes, you know, it takes a fair amount of tweaking to kind of modify things to get them just the way we want. So I'm pretty happy with that level of line thickness. I think it is subtle enough that it's not so pronounced. It doesn't overwhelm the plotting title tiles that we have in here for showing the Z scores. But we can still see where the country borders are. One border that I can't quite see is between Canada and the US. I'm sure it's like right about here. But I think that's okay. I think this is like Michigan that black pixel in the middle there. Anyway, we can certainly see the rest of the countries and where we do and don't have data across the globe for the amount of drought. So I'm pretty happy with the way this looks. I'm going to go ahead and commit these changes to my repository. So I'll go ahead and quit out of here and I get status. Let's make this bigger. And I'll go ahead and add the code plot environment because we added the maps package and then my visuals. So we'll go ahead and add that. Check the status get commit. And we'll say add outline of countries to map. And we'll go ahead and push this up. So I'm trying to push this up to GitHub. But every day GitHub has been making changes because it's been adding new versions of my visual. So I need to first do a get poll to get what's up on the repository down locally. And so I'm getting this warning messages that I need to indicate how to specify how to reconcile the differences. So I'm going to do this get config poll ff only. And so now if we do get poll, let's do a get status to see where we're at. So in these cases where we can't do a fast forward, I'm going to go ahead and do a get fetch. And so what this will do is this will pull down the stuff from the repository without trying to merge it. And so now I can do a get merge. So it's saying there's merge conflicts in visuals world drought.png. That's fine because that's what's actually getting updated each time. So if I do a get status, I'll see that they're both modified here. And so I'm going to go ahead and add that to resolve that. So I'll do a get add on that. And let's go ahead and look at our index.html file to see what that looks like. And this has a whole bunch of stuff. And again, this index file is going to get written over as soon as I push it up there or as soon as it does another iteration of updating for the day. So I'm not totally worried about that either. So I'll go ahead and do a get add on index.html. Make sure this all looks good. And we'll do a get commit to merge remote and local branches. What I should have done was before I committed the changes, I should have pulled down what was up on the repository made my changes committed and then pushed back. What we could do is we can do that get fetch, which is one half of get pull. So we fetch it and then we try to merge it in. There's conflicts. We can then see about resolving those conflicts. I'm not worried about the conflicts because the conflicts are going to get overwritten the next time GitHub actions runs to update the visual on the webpage. So I'll go ahead and commit that and then get push. That now goes up to GitHub smoothly and GitHub actions will do its thing. So here is the updated version of the webpage with today's data. I am really happy with the way this outline looks for the different countries in the visual. I think I'm going to call it here that this is going to be the final version of the figure. I really hope that you've enjoyed watching me develop this online resource. I think we've really flexed a lot of different muscles when it comes to tools that we use for reproducible data analysis. If you have any questions about concepts I've covered over the last series of episodes, please let me know down below in the comments what you'd like to learn more about. Again, we've covered things like using command line interface like bash. We've used VS code. We've used Mamba and Kanda. We've used Snakemake. We've used R. We've used GitHub actions. We used Git in GitHub. Did I mention that already? Anyway, we've used a lot of different tools. And I really think it was cool how they all came together to make an attractive visual that every day is going to get updated. And why can it get updated every day without me touching it? Because it's reproducible, right? We are reproducing this analysis every day with new data. And I think that's pretty awesome. All right. Again, let me know what you think about this. Please tell your friends about what we've done here in today's episode, as well as over the entire series. If you want to go back to the beginning, check out the playlist that I've got over here on my shoulder and enjoy your viewing. All right, take care and I'll see you next time for another episode of Code Club.