Function wraps a ggplot2 geom_linerange to produce a "stick" plot. Function returns a plot object showing vertical/horizontal lines that run from a base value to a measurement value. Options are provided for scaling.
create_stick_plot(
df = NULL,
base_val = 0,
aes_x = NULL,
aes_y = NULL,
aes_color = 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_major_date_breaks = waiver(),
x_date_labels = waiver(),
y_limits = NULL,
y_major_breaks = waiver(),
y_minor_breaks = waiver(),
y_labels = waiver(),
axis_text_size = 11,
line_color = "black",
line_width = 0.8,
line_type = "solid",
line_alpha = 1,
show_major_grids = TRUE,
show_minor_grids = TRUE,
panel_color = "white",
panel_border_color = "black",
show_legend = TRUE,
legend_pos = "right",
legend_key_width = 1.5,
legend_key_height = 1.5,
legend_key_backgrd = "white",
bold_y = NULL,
bold_y_color = "black",
silent_NA_warning = FALSE,
png_file_path = NULL,
png_width_height = c(480, 480)
)
A ggplot class object.
The required target data frame from which the "stick" lines are drawn.
A numeric that sets the base value from which the "stick" originates. The default value is 0.
The required x axis variable name from 'df'. Can be a continuous numeric/Date/POSIXct or discrete factor variable.
The required y axis numeric variable name from 'df' and controls the height of individual "sticks".
Sets the variable name from 'df' for the aesthetic mapping for color.
A string that sets the plot title.
A string that sets the plot subtitle.
A string that sets the plot caption
A logical which if TRUE
centers both the 'title' and 'subtitle'.
A string that sets the x axis title. If NULL
(the default) then the x axis title does not appear.
A string that sets the y axis title. If NULL
(the default) then the y axis title does not appear.
A logical that controls the appearance of the x axis tics.
A logical that controls the appearance of the y axis tics.
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.
A logical which if TRUE rotates the y tic labels 90 degrees for enhanced readability.
Depending on the class of 'aes_x', a numeric/Date/POSIXct 2 element vector that sets the minimum and maximum for the x axis. Use NA to refer to the existing minimum and maximum.
Depending on the class of 'aes_x', a numeric/Date/POSIXct vector or function that defines the exact major tic locations along the x axis.
Depending on the class of 'aes_x', a numeric/Date/POSIXct vector or function that defines the exact minor tic locations along the x axis.
A character vector with the same length as 'x_major_breaks', that labels the major tics.
If the class of 'aes_x' is Date/POSIXct, a string containing the number and date unit for major breaks. Examples: "1 year", "4 sec", "3 month", "2 week".
If the class of 'aes_x' is Date/POSIXct, a string containing the format codes, the
strftime format, for the date. Examples: %Y-%m
, %Y/%b/%d
, %H-%M-%S
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.
A numeric vector or function that defines the exact major tic locations along the y axis.
A numeric vector or function that defines the exact minor tic locations along the y axis.
A character vector with the same length as 'y_major_breaks', that labels the major tics.
A numeric that sets the font size along the axis'. Default is 11.
A string that sets the color attribute of the lines.
A numeric value that sets the width of lines.
A string that sets the linetype. The default is "solid".
A numeric value that sets the degree of color alpha attribute for the lines.
A logical that controls the appearance of major grids.
A logical that controls the appearance of minor grids.
A string in hexidecimal or color name that sets the plot panel's color. The default is "white".
A string in hexidecimal or color name that sets the plot panel's border color. The default is "black".
A logical that controls the appearance of the legend.
A string that sets the legend position. Acceptable values are "top", "bottom", "left", "right".
A numeric that sets the legend width in cm.
A numeric that sets the legend height in cm.
A string that sets the legend's background color.
A numeric that plots a bold horizontal line at this y value.
A string that sets the bold horizontal line color. Default is "black".
A logical that controls the appearance of a console warning when NA's are removed.
A character string with the directory and file name to produce a png image of the plot.
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.
library(ggplot2)
library(RplotterPkg)
RplotterPkg::create_stick_plot(
df = RplotterPkg::air_passengers,
aes_x = "time",
aes_y = "value",
title = "Monthly Totals of International Airline Passengers",
subtitle = "1949 - 1960 (classic Box & Jenkins)",
x_title = "Time",
y_title = "Totals",
x_major_date_breaks = "1 year",
x_date_labels = "%Y",
rot_y_tic_label = TRUE,
show_minor_grids = FALSE,
bold_y = 0.0
)
Run the code above in your browser using DataLab