create_range_plot: create_range_plot

View source: R/create_range_plot.R

create_range_plotR Documentation

create_range_plot

Description

Function wraps ggplot2::geom_pointrange to produce x/y plot of numeric ranges. Function returns a ggplot2 plot object displaying the individual spread or vertical interval/range for a collection of x/y pairs of points.

Usage

create_range_plot(
  df = NULL,
  orientation = "x",
  aes_x = NULL,
  aes_y = NULL,
  aes_min = NULL,
  aes_max = NULL,
  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,
  x_limits = NULL,
  x_major_breaks = waiver(),
  x_minor_breaks = waiver(),
  x_labels = waiver(),
  x_log10 = FALSE,
  y_limits = NULL,
  y_major_breaks = waiver(),
  y_minor_breaks = waiver(),
  y_labels = waiver(),
  y_log10 = FALSE,
  axis_text_size = 11,
  pts_fill = "white",
  pts_shape = 21,
  pts_stroke = 1,
  pts_size = 2,
  line_type = "solid",
  line_width = 1,
  line_pts_color = "black",
  line_pts_alpha = 1,
  panel_color = "white",
  panel_border_color = "black",
  show_major_grids = TRUE,
  show_minor_grids = TRUE,
  bold_x = NULL,
  bold_x_color = "black",
  bold_x_linetype = "dashed",
  bold_y = NULL,
  bold_y_color = "black",
  bold_y_linetype = "dashed",
  silent_NA_warning = FALSE,
  png_file_path = NULL,
  png_width_height = c(480, 480)
)

Arguments

df

The target data frame from which the point ranges are plotted.

orientation

A string that sets the axis on which the range should run along. Acceptable values are either "x" (the default) or "y".

aes_x

Sets the x axis numeric variable name from 'df'.

aes_y

Sets a y axis variable name from 'df'.

aes_min

A string that sets a numeric variable from 'df' that defines the minimum values for the range.

aes_max

A string that sets a numeric variable from 'df' that defines the maximum values for the range.

title

A string that sets the plot title.

subtitle

A string that sets the plot 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.

x_limits

A numeric 2 element vector 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 defines the exact major tic locations along the x axis.

x_minor_breaks

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

x_labels

A character vector with the same length as 'x_major_breaks', that labels the major tics.

x_log10

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

y_limits

A numeric 2 element vector 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 defines the exact major tic locations along the y axis.

y_minor_breaks

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

y_labels

A character vector with the same length as 'y_major_breaks', that labels the major tics.

y_log10

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

axis_text_size

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

pts_fill

A string that sets the fill color of the points.

pts_shape

A numeric integer that sets the shape of the points. Typical values are 21 "circle", 22 "square", 23 "diamond", 24 "up triangle", 25 "down triangle".

pts_stroke

A numeric that sets the drawing width for a point shape.

pts_size

A numeric that sets the point size.

line_type

A string that sets range line type "twodash", "solid", "longdash", "dotted", "dotdash", "dashed", "blank".

line_width

A numeric that sets the width of the lines.

line_pts_color

A string that sets the color of the range lines and outlines of the points.

line_pts_alpha

A numeric value that sets the alpha level of points.

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".

show_major_grids

A logical that controls the appearance of major grids.

show_minor_grids

A logical that controls the appearance of minor grids.

bold_x

A numeric that sets the x-intercept for plotting a bold vertical line.

bold_x_color

A string that sets the color of 'bold_x'.

bold_x_linetype

A string that set the linetype of 'bold_x'.

bold_y

A numeric that sets the y-intercept for plotting a bold horizontal line.

bold_y_color

A string that sets the color of 'bold_y'.

bold_y_linetype

A string that set the linetype of 'bold_y'.

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 ggplot class object.

Examples

library(ggplot2)
library(RplotterPkg)

RplotterPkg::create_range_plot(
  df = RplotterPkg::penguins_stats,
  orientation = "x",
  aes_x = "avg_body_mass",
  aes_y = "species",,
  aes_min = "min_body_mass",
  aes_max = "max_body_mass",
  title = "Average and Range of Penguins Body Mass(g) by Species",
  subtitle = "Source: palmerpenguins",
  center_titles = TRUE,
  x_title = "Body Mass(g)",
  y_title = "Species",
  pts_fill = "blue",
  pts_shape = 22,
  pts_stroke = 1.7,
  line_width = 1.5,
  line_type = "solid",
  line_pts_color = "red",
  line_pts_alpha = 0.5,
  x_limits = c(2500, 7000),
  x_major_breaks = seq(2500,7000,500),
  show_major_grids = TRUE,
  show_minor_grids = FALSE
)


deandevl/RplotterPkg documentation built on March 1, 2025, 11:17 a.m.