ggoutlier_hist: Create a histogram in with outlier bins.

Description Usage Arguments Value Examples

View source: R/ggoutlier_hist.R

Description

Wrapper around 'ggplot2::geom_histogram' in which data points that are considered outliers be binned together. The tick marks under the outlier bins show the entire range of the outliers and the special nature of the outlier bins can be made apperant by giving them a different fill.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
ggoutlier_hist(
  x,
  var_name,
  cut_off_floor = NA_real_,
  cut_off_ceiling = NA_real_,
  col = "black",
  fill = "cornflowerblue",
  fill_outlier_bins = "forestgreen",
  binwidth = NULL
)

Arguments

x

A data frame containing the variable to plot.

var_name

Character indicating which col in 'x' to use.

cut_off_floor

Numeric that indicates what the floor value of the regular range is. All values below this are grouped in the outlier bin on the low end.

cut_off_ceiling

Numeric that indicates what the ceiling value of the regular range is. All values above this are grouped in the outlier bin on the high end.

col

Character that will be used at the col argument of 'ggplot2::geom_histogram'.

fill

Character that will be used at the fill argument of 'ggplot2::geom_histogram' for the regular range.

fill_outlier_bins

Character that will be used at the fill argument of 'ggplot2::geom_histogram' for the outlier bins.

binwidth

Numeric that will be used at the binwith argument of 'ggplot2::geom_histogram'

Value

An object of class 'ggplot'.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
ggoutlier_hist(mtcars, "disp", cut_off_floor = 100)
ggoutlier_hist(mtcars, "disp", cut_off_ceiling = 300)
ggoutlier_hist(mtcars, "disp", cut_off_floor = 100, cut_off_ceiling = 300)
ggoutlier_hist(mtcars, "disp", cut_off_floor = 100, fill = "firebrick")
ggoutlier_hist(mtcars, "disp", cut_off_floor = 100, binwidth = 10)
ggoutlier_hist(mtcars, "disp", cut_off_floor = 100, fill_outlier_bins = "gold")

# Note that the result is a regular ggplot object
#   that you can postprocess the way you want.
p <- ggoutlier_hist(mtcars, "disp", cut_off_floor = 100, cut_off_ceiling = 300)
p + ggplot2::ggtitle("A histogram with binned outliers") +
  ggplot2::ylab("Nr of occurences")

EdwinTh/ggoutlier documentation built on Oct. 26, 2020, 3:51 p.m.