Barplots
Explore barplots and how to plot them in R.
We'll cover the following
Both histograms and boxplots are tools to visualize the distribution of numerical variables. Another commonly desired task is to visualize the distribution of a categorical variable. This is a simpler task because we’re just counting different categories within a categorical variable, also known as levels of the categorical variable. Often the best way to visualize these different counts, also known as frequencies, is with barplots (also called bar charts).
One complication, however, is how our data is represented. Is the categorical variable of interest precounted or not? For example, run the following code that manually creates two data frames representing a collection of fruit—three apples and two oranges.
We see both the fruits
and fruits_counted
data frames represent the same collection of fruit. Whereas fruits
just lists the fruit individually, fruits_counted
has a variable count
that represents the precounted values of each fruit.
Get hands-on with 1400+ tech skills courses.