The gf_vline() function will add a vertical line onto a plot. You can plot the line by referencing a value in a data frame (Example 1), or by specifying the point along the axis where the line should run through (Example 2).
Example 1:
# Save the mean into a data frame using favstats()
Thumb_stats <- favstats(~Thumb, data = Fingers)
# Plot the mean on a histogram with a vertical line
gf_histogram(~Thumb, data = Fingers) %>%
gf_vline( xintercept = ~mean , data = Thumb_stats , color = "blue" , size = 2)
Example of output from running the code above:
Example 2:
# Plot the mean of 60.1 on a histogram with a vertical line
gf_histogram(~Thumb, data = Fingers) %>%
gf_vline( xintercept = 60.1, color = "blue" , size = 2)
Example of output from running the code above:
Related Articles
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_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_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_labs()
The gf_labs() function can be used to modify the labels of your plots. You can add a title for your plot, or modify the label for the x- or y-axis. Example: # Add a title and change the label for the x-axis gf_histogram(~Thumb, data = Fingers) %>% ...