gf_dist()

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 deviation as parameters.

Example 1:

# First save the mean and standard deviation from favstats()
Thumb.stats <- favstats(~ Thumb, data = Fingers)
# Overlay the best fitting normal model (in blue) onto the distribution of Thumb in Fingers
gf_dhistogram(~ Thumb, data = Fingers) %>%
      gf_dist( "norm" , color = "blue" , params = list( Thumb.stats$mean, Thumb.stats$sd ))

Example of output from running the code above:


Example 2:

# Alternatively, you can just directly specify the mean and standard deviation
gf_dhistogram(~ Thumb, data = Fingers) %>%
      gf_dist( "norm" , color = "red" , params = list(mean = 60.10, sd = 8.73))

Example of output from running the code above:




    • Related Articles

    • gf_bar()

      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. ...
    • 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_point()

      The gf_point() function can be used to create a scatterplot, or to plot a specified point, such as a specific value along the x-axis. Example 1: gf_point( Thumb ~ Height , data = Fingers , size = 2 ) Example of output from running the code above: ...
    • gf_jitter()

      The gf_jitter() function will generate a jitter plot. A jitter plot is a point plot (similar to a scatter plot, such as gf_point()) but the points are moved slightly ("jittered") so that they do not overlap as much. This can help make it easier to ...
    • 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 )