f_plot_hist: Plot Histograms

Description Usage Arguments Value Examples

Description

Function plots smart histograms for variables in a data_ls list generated by f_clean_data(). It supports three types of histograms: Bar histograms, density histograms and violin plots. We can further specify a categorical variable to group on. The function defaults to a sensible standard output if key word arguments are not applicable for variable type. Thus we can easily pipe through long lists of variables and thus generate histograms for all variables in the input (see examples).

Usage

1
2
3
4
5
6
f_plot_hist(variable, data_ls, group = "None", graph_type = "violin",
  y_axis = "count", auto_range = T, n_breaks = 30, rug = T,
  x_min = 0, x_max = 100, y_max = 100, title = "",
  col_vector = f_plot_adjust_col_vector_length(100,
  RColorBrewer::brewer.pal(name = "Dark2", n = 8)), p_val = T,
  add = "mean", ...)

Arguments

variable

character vector naming the variable to be plotted

data_ls

data_ls object generated by f_clean_data(), or a named list list( data = <dataframe>, numericals = < vector with column names of numerical columns>)

group

character vector naming the column to be used as grouping variable, Default: NULL

graph_type

one of c("violin", "bar", "line"), Default: 'violin'

y_axis

one of c("count", "density"), Default: c("count", "density")

auto_range

boolean, Default: T

n_breaks

integer , Default: 30

rug

boolean

x_min

double, requires aut_range == F, Default: 0

x_max

double, requires aut_range == F, Default: 100

y_max

double, requires aut_range == F, Default: 100

title

character vector plot title

col_vector

vector with RGB colors, Default: f_plot_adjust_col_vector_length(100, RColorBrewer::brewer.pal(name = "Dark2", n = 8))

p_val

boolean, Default: T

add

character vector one_of( c('mean','median','none') ), This feature is currently enabled because it does not seem to be supported by ggpubr under R 3.5, Default: 'mean'

...

additional arguments passed to labs()

Value

plot object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
#'
#plot single variable
data_ls = f_clean_data(mtcars)
f_plot_hist('disp', data_ls)
f_plot_hist('disp', data_ls, add = 'median')
f_plot_hist('disp', data_ls, add = 'none')
f_plot_hist('disp', data_ls, y_axis = 'density')
f_plot_hist('cyl', data_ls , group = 'gear' )
f_plot_hist('cyl', data_ls , group = 'gear', y_axis = 'density' )
f_plot_hist('cyl', data_ls, y_axis = 'density' )
f_plot_hist('cyl', data_ls, y_axis = 'count' )
f_plot_hist('disp', data_ls, graph_type = 'line', group = 'cyl')
f_plot_hist('disp', data_ls, graph_type = 'bar', group = 'cyl')
f_plot_hist('disp', data_ls, graph_type = 'violin', group = 'cyl'
             , caption ='caption', title = 'title', subtitle = 'subtitle')

#plot all variables
vars = data_ls$all_variables[ data_ls$all_variables != 'cyl' ] %>%
 map( f_plot_hist, data_ls, group = 'cyl')
vars

## End(Not run)

erblast/oetteR documentation built on May 27, 2019, 12:11 p.m.