plot_histogram: Plot nice histogram

View source: R/plot_histogram.R

plot_histogramR Documentation

Plot nice histogram

Description

plot_histogram plots a histogram with a fitted kernel density plot and a normal density plot. If no variable (i.e. NULL) is defined, then for each column in the data frame a histogram is plotted.

Usage

plot_histogram(data, variable = NULL, legend = TRUE)

Arguments

data

is a data frame containing all the data

variable

which variables (i.e. columns) to plot (see examples).

legend

is a boolean (default true) used to show the legend.

Value

ggplot showing a nice histogram

Author(s)

Rico Derks

Examples

set.seed(123)
my_df <- data.frame(a = rnorm(100, mean = 10), 
                    b = rnorm(100, mean = 40),
                    c = rnorm(1000, mean = 123))
                    
# all variables
plot_histogram(data = my_df)

# only one
plot_histogram(data = my_df,
               variable = a)
               
# only two
plot_histogram(data = my_df,
               variable = c(a, b))

# or using tidyverse approach
library(dplyr)
my_df %>%
  plot_histogram()
  

ricoderks/Rcpm documentation built on May 18, 2022, 7:49 a.m.