The gf_dhistogram() function is very similar to the gf_histogram() function, however, the difference is that gf_dhistogram() will create a density histogram for a quantitative variable. This means it will show the percentage of cases for each value of the variable, whereas, gf_histogram() will show the count of the cases for each value of the variable. In other words, a density histogram will give you the relative frequency of values, while, a regular histogram will give you the raw frequency.
A density histogram is also known as a relative frequency histogram.
Example 1:
# Create a density histogram
# Notice the y-axis is labeled as "density" and the units are percentages
gf_dhistogram( ~ Thumb , data = Fingers )
Example of output from running the code above:
Example 2:
# Create a frequency histogram
# Notice the y-axis is labeled as "count" and the units are raw values
gf_histogram( ~ Thumb , data = Fingers )
Example of output from running the code above:
Related Articles
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). ...
gf_dist()
The gf_dist() function can graphically overlay a number of different mathematical probability distributions. If we want to overlay the normal distribution, we’ll have to specify that with the argument “norm”, and then enter in the mean and standard ...
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( ~ ...
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 )