Skip to contents

Producing Histograms

Usage

plotHistogram(
  data = NULL,
  metaData = NULL,
  x = NULL,
  dataMapping = NULL,
  frequency = NULL,
  bins = NULL,
  binwidth = NULL,
  stack = NULL,
  distribution = NULL,
  plotConfiguration = NULL,
  plotObject = NULL
)

Arguments

data

A data.frame to use for plot.

metaData

A named list of information about data such as the dimension and unit of its variables.

x

Numeric values to plot along the x axis. Only used instead of data if data is NULL.

dataMapping

A HistogramDataMapping object mapping x and aesthetic groups to their variable names of data.

frequency

logical defining if histogram displays a frequency in y axis

bins

Number or edges of bins. If bins is provided as a single numeric values, bin corresponds to number of bins. The bin edges are then equally spaced within the range of data. If bins is provided as an array of numeric values, bin corresponds to their edges. Default value, bins=NULL, uses the value defined by dataMapping

binwidth

Numerical value of defining the width of each bin. If defined, binwidth can overwrite bins if bins was not provided or simply provided as a single value. Default value, binwidth=NULL, uses the value defined by dataMapping

stack

Logical defining for multiple histograms if their bars are stacked Default value, stack=NULL, uses the value defined by dataMapping

distribution

Name of distribution to fit to the data. Only 2 distributions are currently available: "normal" and "logNormal" Use distribution="none" to prevent fit of distribution Default value, distribution=NULL, uses the value defined by dataMapping

plotConfiguration

An optional HistogramPlotConfiguration object defining labels, grid, background and watermark.

plotObject

An optional ggplot object on which to add the plot layer

Value

A ggplot object

Examples

# Produce histogram of normally distributed data
plotHistogram(x = rnorm(100))


# Produce histogram of normally distributed data normalized in y axis
plotHistogram(x = rnorm(100), frequency = TRUE)


# Produce histogram of normally distributed data with many bins
plotHistogram(x = rlnorm(100), bins = 21)


# Produce histogram of fitted normally distributed data
plotHistogram(x = rlnorm(100), distribution = "normal")



# Produce histogram of fitted normally distributed data
plotHistogram(x = rlnorm(100), distribution = "normal", frequency = TRUE, stack = TRUE)