Session Ready
Exercise

Making a Bar Graph

We easily can make graphs to visualize our data. Let's visualize the number of manual and automatic transmissions in our car sample through a bar graph, using the function barplot(). The first argument of barplot() is a vector containing the heights of each bar. These heights correspond to the proportional frequencies of a desired measure in your data. You can obtain this information using the table() function.

We are going to make a bar graph of the am (transmission) variable of the mtcars dataset. In this case, the height of the bars can be the frequency of manual and automatic transmission cars. Therefore, here we are going to use table() and barplot() to make this plot.

Remember, you can select a specific variable using either $ or [,]. If you need to look at your data you can simply enter mtcars into your console, or if you just want to check the variables you can always enter str(mtcars) in your console.

Instructions
100 XP
  • In your script, create an object called height using the frequencies of the am variable of the mtcars dataset
  • Use this variable and the barplot() function to create a bar plot of transmission types in our car sample