As we continue building our visualization toolkit, let's consider how to make another kind of classic visualization, a bar plot. We're going to use the same approach that we have in previous videos. Though I will show you a few small variations along the way, and you'll be able to pick up some new tricks. Again, you're going to want to follow along with the R-code that's attached to this video. The R-code has commands for importing the data you need. Again, we're going to use data from the Center for Effective Lawmaking and Cooperative Congressional Election Survey. You'll also find in the materials associated with this video, the teaching data files and the codebooks themselves. The code begins with loading the tidyverse package, and includes the ggplot commands. That includes the ggplot functions, and it also imports the data for you. Let's go ahead and make a bar chart or bar plot, these are interchangeable terms. Let's say that we want a bar chart that shows counts of how many Republicans and Democrats there were in the 115th Congress. There are 435 members of Congress, and this bar plot would show you the number of Democrats and the number of Republicans as two separate bars. Let's start doing some data wrangling and we'll practice using some data piping here. Again, this should be review, but remember that, if you are using piping, what you're doing is passing data from the left-hand of the pipe, which is this percentage sign, the greater than sign percentage sign. You're passing data from the left-hand side of the pipe to the first argument in the function on the right-hand side of the pipe. Here we're taking the CEL data and passing that into the filter command. Filtering the data to include only the rows with values of 115 in the Congress column, so the 115th Congress. Then we're passing those data to the ggplot function. The ggplot function itself, we do our aesthetic mapping. In this particular case, because we're only working with a single variable and the data, which is dem, where 1 means that the member is Democratic and 0 means that the member is a republican. We aren't actually going to set a y value in this aesthetic mapping, because we're only using a single column or variable from the data. This might be a little hard to understand in the abstract, so let's just go ahead and run it and you look at what the output is. What we get is this bar chart with two bars, as I was describing. The bar on the left, set the the value of 0 is the count for how many members in the 115th congress were Republicans, in other words, members with a value of 0 in the dem column and in the bar on the right set at the value of 1, that's the count of the number of members of the 115th congress who were Republicans, in other words, those members that have a value of 1 and the dem column. You can prove that this figure is displaying the data correctly by calling up a frequency table on R, that shows the numbers of 0s and 1s. Now for comparison's sake, let's say that we instead mapped the state name to our aesthetic, rather than the dem variable. What we get now is a figure that provides the count of how many members of Congress there are from each state in the US. The geom_bar function behind the scenes is doing this calculation, adding up the frequency for each distinct entry, so each one of the different states in the US. If you're curious, what would've happened if you mapped this to y instead of x? It does what you might expect, it just flips the figure. Rather than displayed along the x-axis, those frequency counts are displayed on the y-axis. Now let's switch back to the party breakdown figure. One thing that's unsatisfying about the x-axis here is that it's not intuitively labeled. We know from the data that 1 equals Democrat and 0 equals Republicans, but it looks strange in the visualization to see it this way. Let's re-code the dem column and make it something like Democrat and Republican, and add that back into the dataset. Now we changed the aesthetic mapping to this new variable and we plot it again, and it looks a little bit better. But we can improve it by renaming the axis labels using the labs function. Now another thing we've done previously is that we've added color to the plot, so we can do that again by setting the color aesthetic again to the party variable. Still reviewing though, these colors don't make a lot of sense given that the Democrats in the US are usually associated with blue and Republicans with red. We will manually force set color scheme onto the plot by scaling the fill colors manually with the scale fill manual function. Now finally, the legend doesn't really seem necessary here because it's traditionally understood that red is Republican and blue is Democrat in the US. We can drop the legend entirely by adding the guides function to the figure, which controls certain aspects of what legends look like an arm, and we'll just turn off the guides for the fill colors. We've done a lot here, so we're just going to pause for a minute. We're going to pick up with the same R-code file in the next video, and we'll do some more bar plots. Leave your R-file open, maybe go back and review what we've done here, and when you're ready, go on to the next video.