View source: R/histogram-continuous.R
histogram_continuous | R Documentation |
numeric
or integer
variable.Generate a histogram for a numeric
or integer
variable. This graph is intended to quickly provide
the researcher with a quick, yet thorough representation of the continuous variable. The additional annotations may not
be desired for publication-quality plots.
histogram_continuous(
d_observed,
variable_name,
bin_width = NULL,
main_title = base::gsub("_", " ", variable_name, perl = TRUE),
sub_title = NULL,
caption = paste0("each bin is ", scales::comma(bin_width), " units wide"),
x_title = variable_name,
y_title = "Frequency",
x_axis_format = scales::comma_format(),
rounded_digits = 0L,
font_base_size = 12
)
d_observed |
The |
variable_name |
The name of the variable to graph. |
bin_width |
The width of the histogram bins. If NULL, the |
main_title |
The desired title on top of the graph. Defaults to |
sub_title |
The desired subtitle near the top of the graph. Defaults to |
caption |
The desired text in the bottom-right, below the axis. Defaults to the |
x_title |
The desired title on the x-axis. Defaults to the |
y_title |
The desired title on the y-axis. Defaults to “Frequency”. If no axis title is desired, pass a value of |
x_axis_format |
How the x-axis digits are formatted. Defaults to |
rounded_digits |
The number of decimals to show for the mean and median annotations. |
font_base_size |
Sets font size through ggplot2's theme. |
Returns a histogram as a ggplot2
object.
library(datasets)
#Don't run graphs on a headless machine without any the basic graphics packages installed.
if (require(grDevices)) {
# Simple Case
histogram_continuous(
d_observed = beaver1,
variable_name = "temp",
bin_width = .1,
rounded_digits = 2
)
# Variable has no nonmissing values
histogram_continuous(
d_observed = beaver1[integer(0), ],
variable_name = "temp",
bin_width = .1,
rounded_digits = 2
)
# Adjust cosmetics of histogram
histogram_continuous(
d_observed = beaver1,
variable_name = "temp",
bin_width = .1,
rounded_digits = 2,
x_axis_format = scales::comma_format(),
y_title = "Count of 10-min Measurements"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.