mk_histdens | R Documentation |
mk_histdens
takes a data frame as input and returns a function for
making histograms or density plots of any continuous variable from the data
frame. The output function can also produce faceted plots when supplied
a categorical variable for grouping.
mk_histdens(df)
df |
A data frame. |
function(xvar, type = 'histogram', facet_by = NULL, facet_ncol = 1,
add_vline_median = TRUE, add_vline_mean = TRUE,
legend_pos = "right", font_size = 14, ...)
xvar. String, name of a continuous variable for x-axis.
type. String, either 'histogram' (default) or 'density'.
facet_by. String, name of a categorical variable for grouping x and creating facets. Default = NULL.
facet_ncol. Number of columns when facetting. Default = 1. Only works when facet_by is not NULL.
add_vline_median. Logical, if TRUE, add a vertical line at the median of x. Default = TRUE.
add_vline_mean. Logical, if TRUE, add a vertical line at the mean of x. Default = TRUE.
legend_pos. String, legend position. Default = "right".
font_size. Overall font size. Default = 14. The font size of the axes and legend text is a fraction of this value.
.... Other parameters that can be passed into 'ggplot2::geom_histogram()' or 'ggplot2::geom_density()'. For example, 'binwidth' and 'bins' when drawing a histogram. Note 'binwidth' can be specified as a number or a function that calculates width from x. 'bins' (Default = 30) is overridden by 'binwidth', and you almost always want to avoid using its defult value. Andrew Gelman recommends to choose a sufficiently large number to show how raw data are distributed without any smoothing as happens when estimating density. Read this article for details: http://andrewgelman.com/2009/10/23/variations_on_t/. For another example, 'adjust' is a common parameter you want to change when drawing a density plot. Like 'binwidth' and 'bins' when drawing a histogram, it controls the smoothness or jerkinees when drawing the density curve.
get_summ_stats
.
inst/examples/ex-mk_histdens.R
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.