Description Usage Arguments Value Examples
View source: R/plot_histogram.R
plot_hist_with_density
uses dplyr to plot a histogram of a
specific numeric column for a given dataset. It also plots a smooth
density curve overlayed on the histogram. The function also allows
custom parameters to adjust the colours of the plot, bin size, and
alpha transparency.
1 2 3 4 5 6 7 8 9 10 11 12 13 | plot_hist_with_density(
data,
column,
title,
xlab,
ylab = "density",
bins = 20,
alpha = 0.5,
hist_colour = "black",
hist_fill = "white",
density_fill = "grey",
narm = TRUE
)
|
data |
Tibble. The dataset to use for plotting. It is called data because it is a dataset. |
column |
Variable. The variable name for the column to plot.
It must exist as a column in |
title |
String. The title of the plot. It is called title because it is the title of the plot. |
xlab |
String. The x-axis label for the plot. It is called xlab because it is the x-axis label for the plot. |
ylab |
String. The y-axis label for the plot. It is called ylab because it is the x-axis label for the plot. |
bins |
Integer. The number of bins to use for the histogram to plot. It is called bins because it represents the number of bins. |
alpha |
Float. A value in the range |
hist_colour |
String. A string containing either a hex code or a named colour that indicates the colour to use for the histogram outline. It is called hist_colour because it indicates the colour of the histogram outline. |
hist_fill |
String. A string containing either a hex code or a named colour that indicates the colour to use for the histogram fill. It is called hist_fill because it indicates the colour of the histogram fill |
density_fill |
String. A string containing either a hex code or a named colour that indicates the colour to use for the density curve fill. It is called density_fill because it indicates the colour of the density curve fill |
narm |
Boolean. A Boolean value indicting whether or not NA values should be removed from the column to plot. It is called narm because it indicates whether to remove (rm) NA values. |
An image of the plot containing the histogram and density curve
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # Using default parameters
(plot_hist_with_density(
data=iris,
column=Sepal.Length,
xlab="Sepal Length",
title="Histogram and density plot of sepal length"))
# Overwriting default parameters
(plot_hist_with_density(
data=iris,
column=Sepal.Length,
xlab="Sepal Length",
title="Histogram and density plot of sepal length",
bins = 40,
alpha = 0.3,
hist_colour = "grey",
hist_fill = "grey",
density_fill = "blue"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.