let's take a look at an example where we need to build a bar chart okay so here the population in Park City is made up of children working age adults and retirees the table below shows the three age groups the number of people in the city in each age group and the proportion of people in each age group construct a bar graph showing the proportions so before we actually get to constructing the bar graph notice that what we have here is a frequency table with relative frequencies we don't necessarily have those titles in our header column here or in our header row but that's what it is this is telling us how many people are in each category right that's the frequency column this is telling us what percentage each column makes up that means that's a relative frequency column we've given them different names but that's what they in fact are okay now for this example it's asking us to construct a bar graph showing the proportions we have a couple columns here we need to make sure we choose the right one we are interested in the bar graph showing the proportions okay so we're interested in that last column um okay so what do we need for a bar graph we need to know the categories right that's how we label each bar and we need to know the heights of the bar so that's going to be this one so this is going to be the categories the names of the different categories and this will be the height of the different bars okay now we rather than constructing this directly ourselves we're going to let the computer do the hard work for us okay in R we can tell it to construct a bar chart using the bar plot function so we say bar plot and then need to tell it the relevant information so open parenthesis and we tell it what it needs to know so what it needs to know are going to be the height of the bars okay and the names of the bars so we are going to tell it these things so let's see how that works in practice okay my calculator over here so first off I'm going to identify what the Heights and the names are so let's do the heights first um this way so we're going to put the Heights in a list so we start with c c says we're combining these values into a list and then we open the parenthesis and that way what's in between the parenthesis is the values that we're combining in a list okay so if we look at this table we want the heights of the vars reflected by this last column the proportion of the population so we'll have 19.11 percent 43.37 and 37.52 percent okay so 19.11 percent 42.37 and 37.52 percent okay those are going to be the heights of our bars and I've combined them into this list notice I've separated the values with commas when we're writing out a list we put commas in between to say okay now we're going on to the next number okay or the next value I'm going to give this list the name just so we don't have to write out this big long list every time okay I'm going to name it based on where it's coming from so this is the proportion of the population so I'm going to call this list proportions so at the beginning I'll write proportions [Music] and then I'll put an equal sign so that says we're creating a new variable we're calling it proportions and this is its value or in other words this list this is what we're naming it this is the name that list so now whenever the computer sees the word proportions it'll say ah I know what you're talking about you're talking about this list of values okay so that's going to be the heights for my bar chart now I need the names or the labels of each bar okay so the names are going to be the age groups okay and I'm going to put this in a list too so I'm going to combine these values into a list and the age groups are children working age adults and retirees okay so notice a couple things here first off I start off with the c again I want to combine the values into a list the values I'm interested in are between the parentheses so all the values between the parentheses are the ones that are going in the list okay I did something different this time I use these double quotes most the time when the calculator sees just plain words if I took out the double quotes the calculator is going to look and say okay what do you mean by children what thing have you called children just like we called this list proportions the calculator is going to try to find something called children and then it's going to say whoa you never told me what children mean so I'm going to say that this is a mistake and tell you that you have made an error okay I'm not going to run this correctly when we put it in double quotes that tells the calculator don't try to understand this this is just a label okay it's not something for you to interpret okay so whenever we use a plain label that we don't want the calculator to try to understand we put it in double quotes just like um in the above we use commas to separate the different values okay notice the commas are outside the double quotes if I put it inside the double quote the computer is going to think that is part of the label so we put the comma outside the double code say okay this is not part of the label anymore this is telling you that I'm going on to the next thing in the list okay so I have three labels which means three sets of double quotes one set of double quotes for each label okay I'm going to give this a name we call this age groups in the chart so I'm going to do that notice I didn't put a space here the computer wouldn't understand the space when you name something you have to it has to be one word okay so I use a capital G in this case to kind of help me visualize where the break would be but to satisfy the computer I can only do one word so I've made my list this is the the names of the different categories and I've decided to name this list of things age groups so now whenever I use this word in the calculator it'll know ah this is the list you're talking about okay one more thing to notice the the two lists correspond they're in the same order so children the proportion of children was 19.11 percent the proportion of working age adults was 43.37 retirees 37.52 it's important that you keep them in the same order first with first second was second that's how the computer is going to know um which bar is which height okay okay now we have the important stuff out of the way we've told we have um the heights of each bars of each bar we've called that list proportions we have the names of all the bars the category names we've called that list age groups so now we can use that bar plot function okay this is going to create a bar chart with this information so I'm first going to tell the height of the bars and I've stored that in proportions that's what I've named my Heights that's the variable name proportions okay so this is saying telling the computer oh you I the computer's saying okay what are the heights of the bars oh that's this list which I've called proportions okay comma and then we need to tell it what the labels are the names of the different bars are okay so the computer's saying what are the names of the bars and I'm going to say oh I've stored that in the list which I've called age groups okay and then end parenthesis close the parenthesis so that I say okay this is all the information you need to create that bar chart okay I click evaluate it gives me all this information if I scroll down I do indeed get a bar chart notice each bar has labeled with the labels that we've given it children working age adults retirees the way the computer knows is because that's what we told it children working age adults retirees notice the heights of the bars this is just below 20 so that's a 19.11 percent the second bar working age adults is a little bigger than 40 That's the 43.37 percent and the retirees that's oh close to 40 just below 40. that's a 37.52 percent okay so it did all that work automatically of drawing it out all we had to do was give it the information okay and then it used the information we gave it right here we told it what the heights of the bars were we told it what the names of the bars were and it said okay I can use that and I can make a bar chart and it did it okay