f_hist | R Documentation |
This function creates a histogram of the provided data and overlays it with a normal distribution curve.
f_hist(
data,
main = NULL,
xlab = NULL,
probability = TRUE,
col = "white",
border = "black",
line_col = "red",
save_png = FALSE,
open_png = TRUE,
output_file = NULL,
output_dir = NULL,
save_in_wdir = FALSE,
width = 8,
height = 7,
units = "in",
res = 300,
...
)
data |
A numeric vector of data values to be plotted. |
main |
A character string specifying the title of the histogram. Default is |
xlab |
A character string specifying the label for the x-axis. Default is the name of the data variable. |
probability |
A logical value indicating whether to plot a probability or frequency histogram. Default is |
col |
A character string specifying the fill color of the histogram bars. Default is |
border |
A character string specifying the color of the histogram bar borders. Default is |
line_col |
A character string specifying the color of the normal curve line. Default is |
save_png |
A logical value default |
open_png |
Logical. If |
output_file |
Character string specifying the name of the output file (without extension). Default is the name of the vector or dataframe followed by "_histogram.png". |
output_dir |
Character string specifying the name of the directory of the output file. Default is |
save_in_wdir |
Logical. If |
width |
Numeric, png figure width default |
height |
Numeric, png figure height default |
units |
Character string, png figure units default |
res |
Numeric, png figure resolution default |
... |
Additional arguments to be passed to the |
The function first captures the name of the input variable for labeling purposes. It then calculates a sequence of x-values and corresponding y-values for a normal distribution based on the mean and standard deviation of the data. The histogram is plotted with specified aesthetics, and a normal curve is overlaid. To increase resolution you can use png(...,res = 600)
or the 'RStudio' chunk setting, e.g. dpi=600
.
A histogram plot is created and the function returns this as a recordedplot
.
Sander H. van Delden plantmind@proton.me
# Example usage:
set.seed(123)
sample_data <- rnorm(100)
f_hist(sample_data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.