create_histogram_plot: Function wraps ggplot2 geom_histogram to create a histogram.

View source: R/create_histogram_plot.R

create_histogram_plotR Documentation

Function wraps ggplot2 geom_histogram to create a histogram.

Description

Function plots a ggplot2 based histogram with options for scaling and viewing observation locations. The function offers one of four ways of setting the number of bins.

Usage

create_histogram_plot(
  df,
  aes_x = NULL,
  aes_color = NULL,
  aes_fill = NULL,
  position = "stack",
  title = NULL,
  subtitle = NULL,
  caption = NULL,
  center_titles = FALSE,
  x_title = NULL,
  y_title = NULL,
  hide_x_tics = FALSE,
  hide_y_tics = FALSE,
  rot_x_tic_angle = 0,
  rot_y_tic_label = FALSE,
  bins = 20,
  binwidth = NULL,
  bin_breaks = NULL,
  bin_class = NULL,
  bar_fill = NA,
  bar_color = "black",
  bar_alpha = 1,
  bar_size = 1,
  x_limits = NULL,
  x_major_breaks = waiver(),
  x_minor_breaks = waiver(),
  x_labels = waiver(),
  x_decimals = NULL,
  x_scientific = NULL,
  x_log10 = FALSE,
  y_limits = NULL,
  y_major_breaks = waiver(),
  y_minor_breaks = waiver(),
  y_labels = waiver(),
  axis_text_size = 11,
  do_coord_flip = FALSE,
  bar_labels = FALSE,
  bar_label_size = 6,
  bar_label_color = "black",
  plot_obs = FALSE,
  plot_obs_len = 0.02,
  plot_obs_color = "black",
  plot_obs_jitter = FALSE,
  show_major_grids = TRUE,
  show_minor_grids = TRUE,
  show_legend = TRUE,
  panel_color = "white",
  panel_border_color = "black",
  legend_pos = "top",
  legend_key_width = 0.7,
  legend_key_height = 0.7,
  legend_key_backgrd = "white",
  silent_NA_warning = FALSE,
  png_file_path = NULL,
  png_width_height = c(480, 480)
)

Arguments

df

The target data frame for the bar chart.

aes_x

Sets the x axis continuous variable name from df. This argument is required.

aes_color

Sets the variable name from df for the aesthetic mapping for color.

aes_fill

Sets the variable name from df for the aesthetic mapping for fill.

position

A string that sets the bar positions. Acceptable values are dodge, dodge2(side by side), identity(overlap) or stack.

title

A string that sets the overall title.

subtitle

A string that sets the overall subtitle.

caption

A string that sets the plot caption

center_titles

A logical which if TRUE centers both the title and subtitle.

x_title

A string that sets the x axis title. If NULL (the default) then the x axis title does not appear.

y_title

A string that sets the y axis title. If NULL (the default) then the y axis title does not appear.

hide_x_tics

A logical that controls the appearance of the x axis tics.

hide_y_tics

A logical that controls the appearance of the y axis tics.

rot_x_tic_angle

A numeric that sets the angle of rotation for the x tic labels. When x tic labels are long, a value of 40 for this argument usually works well.

rot_y_tic_label

A logical which if TRUE rotates the y tic labels 90 degrees for enhanced readability.

bins

An integer that sets the number of bins of the histogram. Is overridden by a non-null value for either binwidth, bin_breaks or bins_class. Default is 20.

binwidth

A numeric that sets the number of bins based on this value. If aes_x is a date variable then binwidth is the number of days and if a time variable then binwidth is the number of seconds.

bin_breaks

A numeric vector that sets the number of bins by giving the bin boundaries explicitly.

bin_class

A character string that sets the number of bins by selecting one of three types of formulas. Acceptable values are "Sturges", "Scott", or "FD".

bar_fill

A string that sets the fill color attribute for the bars.

bar_color

A string that sets the outline color attribute for the bars.

bar_alpha

A numeric that set the alpha component attribute to bar_color.

bar_size

A numeric that sets the outline thickness of the bars.

x_limits

A numeric 2 element vector or function that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum.

x_major_breaks

A numeric vector or function that sets the major tic locations along the x axis.

x_minor_breaks

A numeric vector or function that sets the minor tic locations along the x axis.

x_labels

A character vector or function giving x axis tic labels. Must be the same length as x_breaks.

x_decimals

A numeric that sets the number of decimal places for x-tic labels.

x_scientific

A logical which if TRUE will put the x-tic labels in scientific notation.

x_log10

A logical which if TRUE will use a log10 scale for the x axis.

y_limits

A numeric 2 element vector or function that sets the minimum and maximum for the y axis. Use NA to refer to the existing minimum and maximum.

y_major_breaks

A numeric vector or function that sets the major tic locations along the y axis.

y_minor_breaks

A numeric vector or function that sets the minor tic locations along the y axis.

y_labels

A character vector or function giving y axis tic labels. Must be the same length as y_breaks.

axis_text_size

A numeric that sets the font size along the axis'. Default is 11.

do_coord_flip

A logical which if TRUE will flip the x and y axis'.

bar_labels

A logical which if TRUE will label each bar with its value.

bar_label_size

A numeric that sets the size of the bar labels

bar_label_color

A string that sets the color of the bar labels

plot_obs

A logical which if TRUE plots a line for each observation along the axis margin.

plot_obs_len

A numeric that sets the length of the plot_obs lines.

plot_obs_color

A string that sets the color of the plot_obs lines.

plot_obs_jitter

A logical which if TRUE will add a slight horizontal adjustment to overlapping observations.

show_major_grids

A logical that controls the appearance of major grids.

show_minor_grids

A logical that controls the appearance of minor grids.

show_legend

A logical that controls the appearance of the legend.

panel_color

A string in hexidecimal or color name that sets the plot panel's color. The default is "white".

panel_border_color

A string in hexidecimal or color name that sets the plot panel's border color. The default is "black".

legend_pos

A string that sets the legend position. Acceptable values are "top", "bottom", "left", "right".

legend_key_width

A numeric that sets the legend width in cm.

legend_key_height

A numeric that sets the legend height in cm.

legend_key_backgrd

A string that sets the legend's background color.

silent_NA_warning

A logical that controls the appearance of a console warning when Na's are removed.

png_file_path

A character string with the directory and file name to produce a png image of the plot.

png_width_height

A numeric vector that sets the width and height of the png image in pixels. The default is c(480,480). There are 37.8 pixels in a centimeter.

Value

A plot object.

Author(s)

Rick Dean


deandevl/RplotterPkg documentation built on Feb. 1, 2024, 8:02 p.m.