View source: R/histogram-date.R
histogram_date | R Documentation |
date
variable.Generate a histogram for a date
variable. This graph is intended to quickly provide
the researcher with a quick, yet thorough representation of the date. The additional annotations may not
be desired for publication-quality plots.
histogram_date(
d_observed,
variable_name,
bin_unit = c("day", "week", "month", "quarter", "year"),
main_title = base::gsub("_", " ", variable_name, perl = TRUE),
sub_title = NULL,
caption = paste0("each bin is 1 ", bin_unit, " wide"),
x_title = variable_name,
y_title = "Frequency",
x_axis_format = scales::comma_format(),
font_base_size = 12
)
d_observed |
The |
variable_name |
The name of the variable to graph. |
bin_unit |
The width of the histogram bins. Value is passed to |
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 |
font_base_size |
Sets font size through ggplot2's theme. |
Returns a histogram as a ggplot2
object.
# Don't run graphs on a headless machine without any the basic graphics packages installed.
if( require(grDevices) & require(nycflights13) ) {
ds <- nycflights13::flights
ds$date_depart <- as.Date(ISOdate(ds$year, ds$month, ds$day))
ds$date_blank <- as.Date(NA)
histogram_date(ds, variable_name="date_depart", bin_unit="day")
histogram_date(ds, variable_name="date_depart", bin_unit="week")
histogram_date(ds, variable_name="date_depart", bin_unit="month")
histogram_date(ds, variable_name="date_depart", bin_unit="quarter")
histogram_date(ds, variable_name="date_depart", bin_unit="year")
histogram_date(ds, variable_name="date_depart", bin_unit="day")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.