 It's LinkedIn Learning author Monica Wahee with today's data science makeover. Watch while Monica Wahee demonstrates how to add error bars to a bar plot using the GG Plot 2 package in R. Alright, the only point of this video is to show you how to add error bars to the bar plot I showed you how to make before. If you missed that, do not worry. Just look in the description to this video and you can watch the prequels. That way, you will better understand the total excitement going on in this video. But first, I want to remind you what I said in one of the videos I linked you to in the description, which is that R package GG Plot, well actually GG Plot 2, likes it when you format the data a certain way before you plot. So let's go look at I already read in this data frame. But let's run this plot data frame I made to look at it again, because I want to show you something. Okay, see these columns? Group is going to be the color of the bar. And that will be in the legend. Measure is going to be our x axis. Basically, those will be the labels of the bars on the x axis. And mean is the value being graph. But look, see that se is standard error. So you need these ingredients in your plot data set to be able to do the error bars, because remember, the error bars are made out of mean and se. And we will refer to these values in our plot code. So let's go back and look at that. Okay, if you watch the other videos, or if you're just a big GG plot fan already, you get what's going on here with this GG plot code. I saved a bunch of hexadecimal colors in a character vector string up here called cool underscore colors. Then I made this bar plot in GG Plot 2, that plotted the measure mean and group. You can see in the AES argument. And then I declare the geome underscore bar, coloring all of the bars black. I specify x and y axis labels, and then declare scale underscore fill underscore manual, and call up my cool underscore colors. This overwrites the black and uses a hexadecimal colors specified in the vector. Okay, that's exciting enough. But then look, this is what this video is all about, this geome underscore error bar line. So notice that the AES argument has a y min and a y max. This is where you specify your interval. As you can see, I just put one se as the error bar. See that y min equals mean minus se. And then y max equals mean plus se. I could have done y min equals mean minus two se or three se. You can actually put arithmetic in there. It's easy to understand this because I named the variables mean and se. But let's say I wanted a 95% confidence interval, I would have needed to cook up an ME, a margin of error, and then put that in my plot data. Or if I actually was good at math, maybe I'd have all the ingredients, the z score, the standard deviation. But actually, I wouldn't do that. Even if I was good at math, you know, in SAS, you want to just plot directly from your big data set. But in R, I think you should just prep cook your plot data sets with all the calculations done offline. So you can make sure they're right, and then just plot it. So if you wanted a 95% confidence interval, just calculate the ME offline, and then put it here and use this kind of code to specify the error bar, just replace se with ME. In fact, I might even just do the two se or the three se offline first. Okay, back to the code. So the width here just specifies the width of the whisker. You know, the horizontal line that goes across the error bar. Is that called a whisker? I can't remember. Okay, and then we need this position dodge, because the chart is not stacked. Okay, everyone ready? Let's highlight and run this plot. Amazing. I just have to say totally amazing. That light blue one is totally significant. Oh, I forgot. This is from a real paper. Here it is. Go read this paper. My friend wrote it. It's pretty good. I linked to it in the description. And my friend has good taste. His data are gorgeous. Thank you for watching this data science makeover with LinkedIn Learning author, Monica Wahee. Remember to check out Monica's data science courses on LinkedIn Learning. Click on the link in the description.