make_plots: Plot and table of summary stats for continuous variables

View source: R/make-eda-plots.R

plot_contR Documentation

Plot and table of summary stats for continuous variables

Description

An opinionated function to plot exploratory data analysis (EDA) type information for an entire data frame, quickly and easily. Given a data frame or tibble, the function will create a plot/table combination depending on the class of the variable or column. Best use is to call this function within a RMarkdown file as part of the initial data exploration. This serves as documentation about the distributions of the variables in a data set.

Usage

plot_cont(
  data,
  var,
  binw_select = "FD",
  subtitle = "Histogram (left), summary statistics (right)"
)

plot_categ(
  data,
  var,
  subtitle = paste0("Bar graph (left), ", "frequency table of top 5 levels (right)")
)

make_plots(df)

Arguments

data

A data frame or tibble

var

Variable or column name

binw_select

Specify method to calculate the bin width. "FD" for Freedman-Diaconis (1981) (default), "Sturges" for Sturges (1926), "Scott" for Scott (1979), "Square-root" for Square-root (N/A), or "Rice" for Rice (1944).

subtitle

String

df

A data frame or tibble

Value

A plot object

A plot object

A plot object

Examples

library(ggplot2)
plot_cont(data = mtcars, var = disp)
plot_cont(data = mtcars, var = disp, binw_select = "Sturges")
plot_cont(data = mtcars, var = disp, binw_select = "Scott")
plot_cont(data = mtcars, var = disp, binw_select = "Rice")

ggplot(data = mtcars, aes(x = disp)) +
  geom_histogram()

ggplot(data = mtcars, aes(x = disp)) +
  geom_histogram(aes(y = ..density..), binwidth = 40) +
  geom_density()

library(dplyr)
library(ggplot2)
mt2 <- mtcars %>%
  mutate(cyl = factor(cyl))

plot_categ(data = mt2, var = cyl)
library(ggplot2)
make_plots(diamonds)

emilelatour/laviz documentation built on Oct. 15, 2023, 1:41 p.m.