histogram: Histogram

View source: R/histogram.R

histogramR Documentation

Histogram

Description

Draw a histogram of a variable in a data frame. The plot thereby mimics the look of SPSS graphs.

Usage

histogram(
  data,
  variable,
  bins = NULL,
  normal = FALSE,
  normal.colour = NULL,
  normal.color = NULL,
  normal.linetype = NULL,
  normal.size = NULL,
  normal.alpha = NULL,
  digits = 3,
  limits = NULL,
  expand = 0.05,
  version = r2spss_options$get("version"),
  ...
)

Arguments

data

a data frame containing the variable to be plotted.

variable

a character string specifying the variable to be plotted.

bins

an integer giving the number of bins for the histogram.

normal

a logical indicating whether to add a normal density with the estimated mean and standard deviation (the default is FALSE).

normal.colour, normal.color, normal.linetype, normal.size, normal.alpha

aesthetics for the normal density. In the unlikely event that both US and UK spellings of color are supplied, the US spelling will take precedence.

digits

an integer giving the number of digits after the comma to be printed in the summary statistics in the right plot margin.

limits

a list of arguments to be passed to expand_limits. Typically, the list would contain components x or y to specify values that should be included in the range of the corresponding axis.

expand

a numeric value specifying the percentage of the range to be used for padding the axes. The default is 0.05 to expand the x-axis by 5% on both sides and the y-axis by 5% on the upper end. Note that there is no padding on lower end of the y-axis to mimic SPSS behavior.

version

a character string specifying whether the plot should mimic the look of recent SPSS versions ("modern") or older versions (<24; "legacy").

...

additional arguments to be passed down, in particular aesthetics (see geom_histogram and geom_line).

Value

An object of class "ggplot", which produces a histogram when printed.

Note

Due to the inner workings of this function to mimic the look of histograms in SPSS, it is not expected that the user adds scale_x_continuous or scale_y_continuous to the plot. Instead, axis limits and padding should be modified via the limits and expand arguments.

Author(s)

Andreas Alfons

Examples

# load data
data("Eredivisie")
# log-transform market values
Eredivisie$logMarketValue <- log(Eredivisie$MarketValue)

# plot histogram of log market values
histogram(Eredivisie, "logMarketValue", normal = TRUE,
          limits = list(x = c(9.5, 17.5)))


r2spss documentation built on May 25, 2022, 5:05 p.m.