Create a histogram plot with a wrapper around the ggplot2::geom_histogram function.
gg_histogram(
data = NULL,
x = NULL,
y = NULL,
col = NULL,
facet = NULL,
facet2 = NULL,
group = NULL,
text = NULL,
stat = "bin",
position = "stack",
pal = NULL,
pal_na = "#7F7F7F",
alpha = 0.9,
...,
titles = NULL,
title = NULL,
subtitle = NULL,
coord = ggplot2::coord_cartesian(clip = "off"),
x_breaks = NULL,
x_expand = NULL,
x_grid = NULL,
x_include = NULL,
x_labels = NULL,
x_limits = NULL,
x_sec_axis = ggplot2::waiver(),
x_title = NULL,
x_trans = "identity",
y_breaks = NULL,
y_expand = NULL,
y_grid = NULL,
y_include = NULL,
y_labels = NULL,
y_limits = NULL,
y_sec_axis = ggplot2::waiver(),
y_title = NULL,
y_trans = "identity",
col_breaks = NULL,
col_continuous = "gradient",
col_include = NULL,
col_labels = NULL,
col_legend_place = NULL,
col_legend_ncol = NULL,
col_legend_nrow = NULL,
col_legend_rev = FALSE,
col_limits = NULL,
col_rescale = NULL,
col_title = NULL,
col_trans = "identity",
facet_labels = NULL,
facet_ncol = NULL,
facet_nrow = NULL,
facet_scales = "fixed",
facet_space = "fixed",
facet_layout = NULL,
caption = NULL,
theme = gg_theme()
)
A ggplot object.
A data frame or tibble.
Unquoted x aesthetic variable.
Unquoted y aesthetic variable.
Unquoted col and fill aesthetic variable.
Unquoted facet aesthetic variable.
Unquoted second facet variable.
Unquoted group aesthetic variable.
Unquoted text aesthetic variable, which can be used in combination with plotly::ggplotly(., tooltip = "text").
Statistical transformation. A character string (e.g. "identity").
Position adjustment. Either a character string (e.g."identity"), or a function (e.g. ggplot2::position_identity()).
Colours to use. A character vector of hex codes (or names).
Colour to use for NA values. A character vector of a hex code (or name).
Opacity. A number between 0 and 1.
Other arguments passed to the relevant ggplot2::geom_* function.
A function to format the x, y and col titles. Defaults to snakecase::to_sentence_case.
Title string.
Subtitle string.
Coordinate system.
A function on the limits (e.g. scales::breaks_pretty()), or a vector of breaks.
Padding to the limits with the ggplot2::expansion function, or a vector of length 2 (e.g. c(0, 0)).
TRUE or FALSE for vertical x gridlines. NULL guesses based on the classes of the x and y.
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.
A vector of length 2 to determine the limits of the axis. Alternatively, zoom in using coord = coord_cartesian(xlim = ...).
A secondary axis using the ggplot2::sec_axis or ggplot2::dup_axis function.
Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.
For a numeric variable, a transformation object (e.g. "log10", "sqrt" or "reverse").
A function on the limits (e.g. scales::breaks_pretty()), or a vector of breaks.
Padding to the limits with the ggplot2::expansion function, or a vector of length 2 (e.g. c(0, 0)).
TRUE or FALSE of horizontal y gridlines. NULL guesses based on the classes of the x and y.
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels.
A vector of length 2 to determine the limits of the axis. Alternatively, zoom in using coord = coord_cartesian(ylim = ...).
A secondary axis using the ggplot2::sec_axis or ggplot2::dup_axis function.
Axis title string. Defaults to converting to sentence case with spaces. Use "" for no title.
For a numeric variable, a transformation object (e.g. "log10", "sqrt" or "reverse").
A function on the limits (e.g. scales::breaks_pretty()), or a vector of breaks.
Type of colouring for a continuous variable. Either "gradient" or "steps". Defaults to "steps" - or just the first letter of these e.g. "g".
For a numeric or date variable, any values that the scale should include (e.g. 0).
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a vector of labels. Note this does not affect where col_intervals is not NULL.
The place for the legend. Either "bottom", "right", "top" or "left" - or just the first letter of these e.g. "b".
The number of columns for the legend elements.
The number of rows for the legend elements.
Reverse the elements of the legend. Defaults to FALSE.
A vector to determine the limits of the colour scale.
For a continuous col variable, a vector to rescale the pal non-linearly.
Legend title string. Defaults to converting to sentence case with spaces. Use "" for no title.
For a numeric variable, a transformation object (e.g. "log10", "sqrt" or "reverse").
A function that takes the breaks as inputs (e.g. scales::label_comma()), or a named vector of labels (e.g. c("value" = "label", ...)).
The number of columns of facets. Only applies to a facet layout of "wrap".
The number of rows of facets. Only applies to a facet layout of "wrap".
Whether facet scales should be "fixed" across facets, "free" in both directions, or free in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed".
Whether facet space should be "fixed" across facets, "free" to be proportional in both directions, or free to be proportional in just one direction (i.e. "free_x" or "free_y"). Defaults to "fixed". Only applies where the facet layout is "grid" and facet scales are not "fixed".
Whether the layout is to be "wrap" or "grid". If NULL and a single facet (or facet2) argument is provided, then defaults to "wrap". If NULL and both facet and facet2 arguments are provided, defaults to "grid".
Caption title string.
A ggplot2 theme.
library(ggplot2)
gg_histogram(diamonds, x = carat)
gg_histogram(diamonds, x = carat, binwidth = 0.01)
gg_histogram(diamonds, x = carat, bins = 200)
gg_histogram(diamonds, y = carat)
gg_histogram(diamonds, x = price, col = cut)
gg_histogram(diamonds, x = price, col = cut, position = "fill")
Run the code above in your browser using DataLab