scandal_histogram_plot: Create a histogram plot

Description Usage Arguments Value Author(s) Examples

View source: R/plotting.R

Description

This function creates a histogram plot i.e. uses bars to visualize the frequency distribution of data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
scandal_histogram_plot(
  data,
  title = NULL,
  xlab = NULL,
  ylab = "Frequency",
  by = 0.2,
  title_text_size = 20,
  colour = "black",
  fill = "lightblue",
  alpha = 0.2
)

Arguments

data

a numeric vector of observations.

title

an optional string for the title of the plot. Default is NULL (no title).

xlab

a label for the x axis. Default is NULL (no label).

ylab

a label for the y axis. Default is "Frequency".

by

controls the binwidth. Default is 0.2.

title_text_size

text size of the title. Default is 20.

colour

color of the border of the histogram bars. Default is "black".

fill

fill color of the histogram bars. Default is "lightblue".

alpha

transparency of the histogram bars fill color. Default is 0.2.

Value

A ggplot2 object representing the histogram plot.

Author(s)

Avishay Spitzer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Generate 10K normally distributed data points
y <- rnorm(10000, mean = 5, sd = 1)

# Generate the histogram plot with bin width of 0.2
scandal_histogram_plot(y, by = .2)

library(ggplot2)

# Generate the histogram plot with bin width of 0.2. Ad the function returns a ggplot object
# we can attach to it a vertical line marking the mean of the distribution with regular
# ggplot arithmetics
scandal_histogram_plot(y, by = .2) +
    geom_vline(xintercept = mean(y), colour = "red", linetype = "dashed", size = 1)

# Same example with bin width 0.5
scandal_histogram_plot(y, by = .5) +
    geom_vline(xintercept = mean(y), colour = "red", linetype = "dashed", size = 1)

dravishays/scandal documentation built on Jan. 8, 2020, 1:30 p.m.