The gf_bar() function creates a bar graph. It can be used to visualize the distribution of a categorical variable by counting the number of observations for each group of the category.
Bar graphs can also be used with the gf_facet_grid() function.
Example 1:
gf_bar( ~ Sex , data = Fingers )
Example of output from running the code above:
Example 2:
gf_bar( ~ RaceEthnic, data = Fingers) %>%
gf_facet_grid(Sex ~ .)
Example of output from running the code above:
Related Articles
gf_facet_grid()
The gf_facet_grid() function will create separate plots for each group of a categorical variable. It can be chained onto plots such as gf_histogram(), gf_jitter(), and gf_bar(). Example 1: # Density histogram of Thumb faceted by Sex gf_dhistogram( ~ ...
Bar Graphs vs Histograms
What is the difference between a bar graph and a histogram? Bar graphs and histograms are both visualizations of data, but they visualize different types of data. Bar graphs are used for categorical variables, while histograms are used for ...
gf_lm()
The gf_lm() function overlays the best-fitting regression line on a scatter plot when chained onto gf_point(). Example: # adds a regression line gf_point(Thumb ~ Height, data = Fingers) %>% gf_lm( color = "orange", size = 2 )
gf_density()
The gf_density() function will overlay a density plot onto a density histogram (i.e., gf_dhistogram(), not gf_histogram()). The density plot is a smoothed out version of the distribution. They can be helpful when you want to get a better idea of the ...
gf_histogram()
The gf_histogram() function will create a frequency histogram for a quantitative variable. This means it will show the number of cases observed in the data for each value of the variable. (See gf_dhistogram() for information on density histograms). ...