Description Usage Arguments Value Author(s) Examples
This function creates a histogram plot i.e. uses bars to visualize
the frequency distribution of data
.
1 2 3 4 5 6 7 8 9 10 11 |
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. |
A ggplot2 object representing the histogram plot.
Avishay Spitzer
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.