Skip to contents

Overlays a rescaled histogram or density curve on the existing plot, using the x-axis variable (or a user-supplied variable).

Usage

fmt_his(
  plot,
  type = c("histogram", "density", "h", "d"),
  height_ratio = 0.3,
  data = NULL,
  con_var = NULL,
  ...
)

Arguments

plot

A ggplot, patchwork, or list of ggplots.

type

"histogram" (or "h") or "density" (or "d").

height_ratio

Fraction of the y-axis range used for the overlay height.

data

Optional data frame. If NULL, uses the plot data.

con_var

Variable name for the x-axis. If NULL, extracted from the plot mapping.

...

Additional arguments: binwidth, adjust, his_color, his_alpha, y_rescale, ylim.

Value

Same type as input.

Examples

if (FALSE) { # \dontrun{
library(ggplot2)
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()
fmt_his(p, type = "histogram", height_ratio = 0.3)
fmt_his(p, type = "density", height_ratio = 0.2)
} # }