| Title: | Command Line Interface Plotting |
|---|---|
| Description: | The 'plotcli' package provides terminal-based plotting in R. It supports colored scatter plots, line plots, bar plots, boxplots, histograms, density plots, heatmaps, and more. The 'ggplotcli()' function is a universal converter that renders any 'ggplot2' plot in the terminal using Unicode Braille characters or ASCII. Features include support for 27 geom types, faceting (facet_wrap/facet_grid), automatic theme detection, legends, optimized color mapping, and multiple canvas types. |
| Authors: | Claas Heuer [aut, cre] |
| Maintainer: | Claas Heuer <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.3.0 |
| Built: | 2026-05-13 08:55:55 UTC |
| Source: | https://github.com/cheuerde/plotcli |
This function overloads the "+" operator to merge two plotcli objects.
## S3 method for class 'plotcli' plot1 + plot2## S3 method for class 'plotcli' plot1 + plot2
plot1 |
A plotcli object to be merged. |
plot2 |
A plotcli object to be merged. |
A new plotcli object containing the combined data from both objects.
ASCII Canvas Class
ASCII Canvas Class
Simple canvas using basic ASCII characters. Resolution: 1x1 (one pixel per character)
plotcli::Canvas -> AsciiCanvas
point_charCharacter used for points
plotcli::Canvas$apply_colors()plotcli::Canvas$clear()plotcli::Canvas$draw_circle()plotcli::Canvas$draw_hline()plotcli::Canvas$draw_line()plotcli::Canvas$draw_points()plotcli::Canvas$draw_polygon()plotcli::Canvas$draw_polyline()plotcli::Canvas$draw_rect()plotcli::Canvas$draw_segment()plotcli::Canvas$draw_text()plotcli::Canvas$draw_vline()plotcli::Canvas$fill_area()plotcli::Canvas$fill_bar()plotcli::Canvas$fill_circle()plotcli::Canvas$fill_rect()plotcli::Canvas$print()plotcli::Canvas$render()new()
Initialize ASCII canvas
AsciiCanvas$new(width, height, point_char = "*")
widthCharacter width
heightCharacter height
point_charCharacter to use for points (default "*")
set_pixel()
Set a pixel
AsciiCanvas$set_pixel(x, y, color = NULL)
xX coordinate (1-based)
yY coordinate (1-based, 1 = top)
colorOptional color name
clone()
The objects of this class are cloneable with this method.
AsciiCanvas$clone(deep = FALSE)
deepWhether to make a deep clone.
Block Canvas Class
Block Canvas Class
Canvas using Unicode block elements for 2x vertical resolution. Uses half-block characters: upper half (U+2580), lower half (U+2584), full block (U+2588).
Resolution: 1x2 (1 horizontal, 2 vertical pixels per character)
plotcli::Canvas -> BlockCanvas
upper_blockUpper half block character
lower_blockLower half block character
full_blockFull block character
pixel_stateMatrix tracking which half-pixels are set (0=none, 1=upper, 2=lower, 3=both)
plotcli::Canvas$apply_colors()plotcli::Canvas$draw_circle()plotcli::Canvas$draw_hline()plotcli::Canvas$draw_line()plotcli::Canvas$draw_points()plotcli::Canvas$draw_polygon()plotcli::Canvas$draw_polyline()plotcli::Canvas$draw_rect()plotcli::Canvas$draw_segment()plotcli::Canvas$draw_text()plotcli::Canvas$draw_vline()plotcli::Canvas$fill_area()plotcli::Canvas$fill_bar()plotcli::Canvas$fill_circle()plotcli::Canvas$fill_rect()plotcli::Canvas$print()plotcli::Canvas$render()new()
Initialize Block canvas
BlockCanvas$new(width, height)
widthCharacter width
heightCharacter height
set_pixel()
Set a pixel in Block space
BlockCanvas$set_pixel(x, y, color = NULL)
xX coordinate (1-based, in pixel space: 1 to width)
yY coordinate (1-based, in pixel space: 1 to height*2, 1 = top)
colorOptional color name
clear()
Clear the canvas
BlockCanvas$clear()
clone()
The objects of this class are cloneable with this method.
BlockCanvas$clone(deep = FALSE)
deepWhether to make a deep clone.
Returns the bit value for a specific dot position in a Braille cell. Braille cells have a 2x4 dot matrix with the following bit values:
braille_dot_bit(dot_row, dot_col)braille_dot_bit(dot_row, dot_col)
dot_row |
Row within the Braille cell (0-3, top to bottom) |
dot_col |
Column within the Braille cell (0-1, left to right) |
Col 0 Col 1
Row 0: 0x01 0x08
Row 1: 0x02 0x10
Row 2: 0x04 0x20
Row 3: 0x40 0x80
The bit value for that dot position
Set a dot in a Braille character
braille_set_dot(current_char, dot_row, dot_col)braille_set_dot(current_char, dot_row, dot_col)
current_char |
The current character (can be space or existing Braille) |
dot_row |
Row within the Braille cell (0-3) |
dot_col |
Column within the Braille cell (0-1) |
The updated Braille character
Braille Canvas Class
Braille Canvas Class
High-resolution canvas using Unicode Braille patterns. Resolution: 2x4 (2 horizontal, 4 vertical dots per character = 8x resolution)
Braille dot layout (dot numbers and bit values):
Col 0 Col 1 Bit values
Row 0: 1 4 0x01 0x08
Row 1: 2 5 0x02 0x10
Row 2: 3 6 0x04 0x20
Row 3: 7 8 0x40 0x80
plotcli::Canvas -> BrailleCanvas
braille_baseUnicode code point for empty Braille character
plotcli::Canvas$apply_colors()plotcli::Canvas$clear()plotcli::Canvas$draw_circle()plotcli::Canvas$draw_hline()plotcli::Canvas$draw_line()plotcli::Canvas$draw_points()plotcli::Canvas$draw_polygon()plotcli::Canvas$draw_polyline()plotcli::Canvas$draw_rect()plotcli::Canvas$draw_segment()plotcli::Canvas$draw_text()plotcli::Canvas$draw_vline()plotcli::Canvas$fill_area()plotcli::Canvas$fill_bar()plotcli::Canvas$fill_circle()plotcli::Canvas$fill_rect()plotcli::Canvas$print()plotcli::Canvas$render()new()
Initialize Braille canvas
BrailleCanvas$new(width, height)
widthCharacter width
heightCharacter height
get_dot_bit()
Get the bit value for a dot position
BrailleCanvas$get_dot_bit(dot_row, dot_col)
dot_rowRow within Braille cell (0-3)
dot_colColumn within Braille cell (0-1)
Bit value
set_pixel()
Set a pixel in Braille space
BrailleCanvas$set_pixel(x, y, color = NULL)
xX coordinate (1-based, in pixel space: 1 to width*2)
yY coordinate (1-based, in pixel space: 1 to height*4, 1 = top)
colorOptional color name
clone()
The objects of this class are cloneable with this method.
BrailleCanvas$clone(deep = FALSE)
deepWhether to make a deep clone.
This function generates a list of points that form a line between two given points using Bresenham's line algorithm.
bresenham(x0, y0, x1, y1)bresenham(x0, y0, x1, y1)
x0 |
The x-coordinate of the starting point. |
y0 |
The y-coordinate of the starting point. |
x1 |
The x-coordinate of the ending point. |
y1 |
The y-coordinate of the ending point. |
A list of points that form a line between the two given points.
bresenham(0, 0, 5, 5) bresenham(0, 0, -5, -5)bresenham(0, 0, 5, 5) bresenham(0, 0, -5, -5)
Abstract canvas system that provides different rendering backends: - AsciiCanvas: Basic ASCII characters (*, -, |, +) - BrailleCanvas: Unicode Braille patterns (2x4 dots per cell = 8x resolution) - BlockCanvas: Unicode block elements (half-blocks for 2x vertical resolution)
Abstract base class for all canvas types. Provides the interface that all canvas implementations must follow.
widthCharacter width of the canvas
heightCharacter height of the canvas
pixel_widthPixel width (may be higher than char width for Braille/Block)
pixel_heightPixel height (may be higher than char height for Braille/Block)
matrixCharacter matrix for rendering
color_matrixParallel matrix tracking colors per cell
x_multHorizontal multiplier (pixels per character)
y_multVertical multiplier (pixels per character)
new()
Initialize the canvas
Canvas$new(width, height)
widthCharacter width
heightCharacter height
set_pixel()
Set a pixel at the given coordinates
Canvas$set_pixel(x, y, color = NULL)
xX coordinate (1-based, in pixel space)
yY coordinate (1-based, in pixel space, 1 = top)
colorOptional color name
draw_line()
Draw a line between two points
Canvas$draw_line(x0, y0, x1, y1, color = NULL)
x0Start X coordinate
y0Start Y coordinate
x1End X coordinate
y1End Y coordinate
colorOptional color name
draw_polyline()
Draw multiple connected line segments
Canvas$draw_polyline(xs, ys, color = NULL)
xsVector of X coordinates
ysVector of Y coordinates
colorOptional color name
draw_points()
Draw points (scatter)
Canvas$draw_points(xs, ys, color = NULL)
xsVector of X coordinates
ysVector of Y coordinates
colorOptional color name
fill_rect()
Fill a rectangle
Canvas$fill_rect(x0, y0, x1, y1, color = NULL)
x0Left X coordinate
y0Top Y coordinate
x1Right X coordinate
y1Bottom Y coordinate
colorOptional color name
fill_bar()
Fill a vertical bar from bottom up to a height
Canvas$fill_bar(x, height, bar_width = 2, color = NULL)
xX coordinate (center of bar in pixel space)
heightHeight in pixels from bottom
bar_widthWidth of bar in pixels (default 2)
colorOptional color name
draw_text()
Place text at a position
Canvas$draw_text(x, y, text, color = NULL)
xX coordinate (character position)
yY coordinate (character position)
textText string to place
colorOptional color name
apply_colors()
Apply colors to the matrix
Canvas$apply_colors()
Matrix with ANSI color codes applied
render()
Get the rendered matrix (with colors)
Canvas$render()
Character matrix
print()
Print the canvas to console
Canvas$print()
clear()
Clear the canvas
Canvas$clear()
draw_rect()
Draw a rectangle outline
Canvas$draw_rect(x0, y0, x1, y1, color = NULL)
x0Left X coordinate (pixel space)
y0Top Y coordinate (pixel space)
x1Right X coordinate (pixel space)
y1Bottom Y coordinate (pixel space)
colorOptional color name
fill_area()
Fill an area between a polyline and the bottom
Canvas$fill_area(xs, ys, color = NULL)
xsVector of X coordinates
ysVector of Y coordinates
colorOptional color name
draw_segment()
Draw a segment (line with optional arrowhead)
Canvas$draw_segment(x0, y0, x1, y1, arrow_end = FALSE, color = NULL)
x0Start X coordinate
y0Start Y coordinate
x1End X coordinate
y1End Y coordinate
arrow_endAdd arrowhead at end (default FALSE)
colorOptional color name
draw_hline()
Draw a horizontal line
Canvas$draw_hline(y, x0 = 1, x1 = NULL, color = NULL)
yY coordinate
x0Start X (default 1)
x1End X (default pixel_width)
colorOptional color name
draw_vline()
Draw a vertical line
Canvas$draw_vline(x, y0 = 1, y1 = NULL, color = NULL)
xX coordinate
y0Start Y (default 1)
y1End Y (default pixel_height)
colorOptional color name
draw_circle()
Draw a circle outline
Canvas$draw_circle(cx, cy, r, color = NULL)
cxCenter X coordinate
cyCenter Y coordinate
rRadius in pixels
colorOptional color name
fill_circle()
Fill a circle
Canvas$fill_circle(cx, cy, r, color = NULL)
cxCenter X coordinate
cyCenter Y coordinate
rRadius in pixels
colorOptional color name
draw_polygon()
Draw a polygon outline
Canvas$draw_polygon(xs, ys, closed = TRUE, color = NULL)
xsVector of X coordinates
ysVector of Y coordinates
closedWhether to close the polygon (default TRUE)
colorOptional color name
clone()
The objects of this class are cloneable with this method.
Canvas$clone(deep = FALSE)
deepWhether to make a deep clone.
This function prints a plot matrix to the console.
cat_plot_matrix(plot_matrix)cat_plot_matrix(plot_matrix)
plot_matrix |
The plot matrix to be printed. |
cat_plot_matrix(matrix(c("a", "b", "c", "d"), nrow = 2, ncol = 2))cat_plot_matrix(matrix(c("a", "b", "c", "d"), nrow = 2, ncol = 2))
This function combines multiple plot matrices horizontally, centering them vertically.
cbind_plots(...)cbind_plots(...)
... |
A list of plot matrices to be combined. |
A combined plot matrix.
Generic function for combining plotcli objects horizontally
## S3 method for class 'plotcli' cbind(..., deparse.level = 1)## S3 method for class 'plotcli' cbind(..., deparse.level = 1)
... |
plotcli objects to be combined. |
deparse.level |
The deparsing level for the arguments. |
A combined plot matrix.
If init_color_mapping() was called, uses the pre-computed mapping. Otherwise falls back to simple hue-based matching.
color_to_term(color)color_to_term(color)
color |
A color value (hex, name, or R color) |
A terminal color name (blue, red, green, etc.) or NULL
Create a canvas of the specified type
create_canvas(width, height, type = "braille")create_canvas(width, height, type = "braille")
width |
Character width |
height |
Character height |
type |
Canvas type: "ascii", "braille", or "block" |
A Canvas object
Create Scale Object from ggplot_build data
create_scales(built, plot_width, plot_height, has_border = FALSE, x_mult = 1, y_mult = 1)create_scales(built, plot_width, plot_height, has_border = FALSE, x_mult = 1, y_mult = 1)
built |
Result from ggplot_build() |
plot_width |
Canvas pixel width |
plot_height |
Canvas pixel height |
has_border |
Whether a border will be drawn (adds padding) |
x_mult |
X multiplier for canvas type (e.g., 2 for braille) |
y_mult |
Y multiplier for canvas type (e.g., 4 for braille) |
List with x_scale and y_scale functions
This function formats a number to a string of exactly four characters.
format_four_chars(num)format_four_chars(num)
num |
The number to be formatted. |
A string representation of the number with exactly four characters.
format_four_chars(123) format_four_chars(-12.34)format_four_chars(123) format_four_chars(-12.34)
This module provides a registry for geom rendering functions and a dispatch system for converting ggplot2 geoms to terminal plots.
This function returns a subset of the data for a specific geom.
get_data_subset(geom_name, data, aes, p_build)get_data_subset(geom_name, data, aes, p_build)
geom_name |
The name of the geom for which the data subset is needed. |
data |
The data to be subsetted. |
aes |
The aesthetic mappings for the geom. |
p_build |
The ggplot build object. |
A list containing the data subset for the specified geom.
Retrieve the registered handler for a geom, or NULL if not found.
get_geom_handler(geom_name)get_geom_handler(geom_name)
geom_name |
Name of the geom |
The handler function or NULL
This function returns a vector of terminal colors.
get_term_colors(n = NULL)get_term_colors(n = NULL)
n |
The number of colors to return. |
A vector of terminal colors.
get_term_colors(5) get_term_colors(10)get_term_colors(5) get_term_colors(10)
Convert any ggplot2 plot to a terminal-based visualization using Unicode Braille characters or ASCII. Supports 15+ geom types, faceting, themes, and color aesthetics.
ggplotcli( p, width = 60, height = 20, canvas_type = "braille", border = "auto", grid = "none", show_axes = TRUE, axis_labels = TRUE, legend = "auto", title_align = "center", subtitle = TRUE, caption = TRUE, title = NULL, boxplot_style = "ascii" )ggplotcli( p, width = 60, height = 20, canvas_type = "braille", border = "auto", grid = "none", show_axes = TRUE, axis_labels = TRUE, legend = "auto", title_align = "center", subtitle = TRUE, caption = TRUE, title = NULL, boxplot_style = "ascii" )
p |
A ggplot2 object to render |
width |
Character width of the plot (default: 60) |
height |
Character height of the plot (default: 20) |
canvas_type |
Type of canvas: "braille" (high-res), "block" (medium), or "ascii" (basic). Default: "braille" |
border |
Draw border around plot. "auto" uses ggplot theme, or TRUE/FALSE (default: "auto") |
grid |
Grid lines: "none", "major", "minor", "both", or "auto" (default: "none") |
show_axes |
Whether to show axis values (default: TRUE) |
axis_labels |
Whether to show axis labels from ggplot (default: TRUE) |
legend |
Legend display: "auto", "right", "bottom", "none" (default: "auto") |
title_align |
Title alignment: "center" or "left" (default: "center") |
subtitle |
Whether to show subtitle (default: TRUE) |
caption |
Whether to show caption (default: TRUE) |
title |
Optional title override (NULL uses ggplot title) |
boxplot_style |
Style for boxplots: "ascii" uses box-drawing characters (default), "braille" uses Braille dots like other geoms |
Invisibly returns the canvas object
library(ggplot2) # Basic scatter plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() ggplotcli(p) # With styling ggplotcli(p, border = TRUE, grid = "major") # Faceted plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_wrap(~cyl) ggplotcli(p, width = 70, height = 16) # Multiple geoms p <- ggplot(mtcars, aes(x = mpg)) + geom_histogram(aes(y = after_stat(density)), bins = 10) + geom_density(color = "red") ggplotcli(p)library(ggplot2) # Basic scatter plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() ggplotcli(p) # With styling ggplotcli(p, border = TRUE, grid = "major") # Faceted plot p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() + facet_wrap(~cyl) ggplotcli(p, width = 70, height = 16) # Multiple geoms p <- ggplot(mtcars, aes(x = mpg)) + geom_histogram(aes(y = after_stat(density)), bins = 10) + geom_density(color = "red") ggplotcli(p)
This function takes all unique colors from a ggplot and assigns terminal colors to minimize repetition while respecting hue similarity.
init_color_mapping(ggplot_colors)init_color_mapping(ggplot_colors)
ggplot_colors |
Vector of unique colors from ggplot |
This function checks if a given character is a Braille character.
is_braille(char)is_braille(char)
char |
The character to be checked. |
A boolean value indicating whether the character is a Braille character or not.
is_braille("A")is_braille("A")
Check if a Geom is Registered
is_geom_registered(geom_name)is_geom_registered(geom_name)
geom_name |
Name of the geom |
Logical
List Registered Geoms
list_registered_geoms()list_registered_geoms()
Character vector of registered geom names
This function applies a specified color to a given text string.
make_colored(x, color = NULL)make_colored(x, color = NULL)
x |
The text string to be colored. |
color |
The color to be applied to the text. If NULL, the color codes will be removed. |
A colored text string or a text string with color codes removed.
make_colored("Hello, world!", "blue") make_colored("Hello, world!", NULL)make_colored("Hello, world!", "blue") make_colored("Hello, world!", NULL)
This function takes a vector of names and ensures that each name is unique by appending a number if necessary.
make_unique_names(names)make_unique_names(names)
names |
A character vector of names. |
A character vector of unique names.
make_unique_names(c("apple", "apple", "banana", "apple"))make_unique_names(c("apple", "apple", "banana", "apple"))
This function normalizes the given data to a specified plot range.
normalize_data(data, data_min, data_max, plot_range)normalize_data(data, data_min, data_max, plot_range)
data |
The data to be normalized. |
data_min |
The minimum value of the data. |
data_max |
The maximum value of the data. |
plot_range |
The range to normalize the data to. |
The normalized data.
normalize_data(c(1, 2, 3, 4, 5), 1, 5, 10) normalize_data(c(10, 20, 30, 40, 50), 10, 50, 100)normalize_data(c(1, 2, 3, 4, 5), 1, 5, 10) normalize_data(c(10, 20, 30, 40, 50), 10, 50, 100)
Short version of plotcli_bar function.
pclib( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "barplot", ... )pclib( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "barplot", ... )
y |
A numeric vector of values |
x |
A vector of categories |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "barplot") |
... |
Additional arguments passed to the plotcli$new() function |
x <- 1:5 y <- c(10, 15, 8, 12, 6) pclib(x, y)x <- 1:5 y <- c(10, 15, 8, 12, 6) pclib(x, y)
Short version of plotcli_box function.
pclibx( y, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "boxplot", ... )pclibx( y, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "boxplot", ... )
y |
A list of numeric vectors of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "boxplot") |
... |
Additional arguments passed to the plotcli$new() function |
x |
A vector of categories |
y <- rnorm(50, mean = 0) pclib(y)y <- rnorm(50, mean = 0) pclib(y)
Short version of plotcli_density function.
pclid( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Density", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "density", ... )pclid( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Density", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "density", ... )
x |
A numeric vector of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "Density") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "density") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) pclid(x)x <- rnorm(100) pclid(x)
Short version of plotcli_histogram function.
pclih( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Frequency", color = NULL, braille = getOption("plotcli.braille", TRUE), bin_width = NULL, ylim = NULL, name = "histogram", ... )pclih( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Frequency", color = NULL, braille = getOption("plotcli.braille", TRUE), bin_width = NULL, ylim = NULL, name = "histogram", ... )
x |
A numeric vector of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "Frequency") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
bin_width |
Width of the bins (default: NULL) |
ylim |
y limits (default: NULL) |
name |
Name of the plot element (default: "histogram") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) pclih(x)x <- rnorm(100) pclih(x)
Short version of plotcli_line function.
pclil( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "line", ... )pclil( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "line", ... )
y |
A numeric vector of y values |
x |
A numeric vector of x values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "line") |
... |
Additional arguments passed to the plotcli$new() function |
x <- 1:10 y <- x^2 pclil(x, y)x <- 1:10 y <- x^2 pclil(x, y)
Short version of plotcli_scatter function.
pclis( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "scatter", ... )pclis( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "scatter", ... )
y |
A numeric vector of y values |
x |
A numeric vector of x values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "scatter") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) y <- rnorm(100) pclis(x, y)x <- rnorm(100) y <- rnorm(100) pclis(x, y)
Convert pixel coordinates to Braille cell and dot position
pixel_to_braille(px, py, canvas_rows, canvas_cols)pixel_to_braille(px, py, canvas_rows, canvas_cols)
px |
Pixel x coordinate (1-based) |
py |
Pixel y coordinate (1-based, from top) |
canvas_rows |
Number of character rows in canvas |
canvas_cols |
Number of character columns in canvas |
List with cell_row, cell_col, dot_row, dot_col
plotcli R6 Class
plotcli R6 Class
This class provides a set of methods to create and customize command-line plots using R6. It supports various plot types, such as scatter, line, bar, and box plots, and allows customization of plot elements, such as title, axis labels, ticks, and legend.
plotcli <- plotcli$new() plotcli$add_data(data) plotcli$print_plot()
Initializes the PlotCLI object with parameters.
Initializes the plot matrix with the plot canvas.
Default print method for PlotCLI object.
Adds a single row to the plot matrix.
Adds a single column to the plot matrix.
Adds borders around the plot canvas.
Adds row and column index to the plot matrix.
Adds a title to the plot matrix.
Adds y-axis tick labels to the plot matrix.
Adds a y-axis label to the plot matrix.
Adds x-axis tick labels to the plot matrix.
Adds an x-axis label to the plot matrix.
Adds a legend to the plot matrix.
Adds data to the object.
Gets minimum and maximum values for x and y.
Removes out of range data points if xlim and ylim were given.
Draws a scatter plot on the plot canvas.
Draws a line plot on the plot canvas.
Draws a bar plot on the plot canvas.
Draws a bar plot with braille characters on the plot canvas.
Draws a box plot on the plot canvas.
Assembles all plot elements and prints the plot to the console.
plot_widthThe width of the plot
plot_heightThe height of the plot
plot_canvasThe canvas for drawing the plot
plot_matrixThe matrix containing the entire plot, including borders, labels, and title
dataA list containing the data sets to be plotted
titleThe title of the plot
x_labelThe label for the x-axis
y_labelThe label for the y-axis
ylimThe limits for the y-axis
xlimThe limits for the x-axis
x_minThe minimum value of the x-axis
x_maxThe maximum value of the x-axis
y_minThe minimum value of the y-axis
y_maxThe maximum value of the y-axis
plot_matrix_canvas_row_startThe starting row of the plot canvas within the plot matrix
plot_matrix_canvas_col_startThe starting column of the plot canvas within the plot matrix
is_boxplotA logical value indicating if the plot is a boxplot
draw_legendA logical value indicating if the legend should be drawn
new()
Initialize object
plotcli$new( plot_width = 60, plot_height = 20, x_label = "x", y_label = "y", ylim = NULL, xlim = NULL, title = NULL, is_boxplot = FALSE, draw_legend = TRUE )
plot_widthinteger, width of the plot canvas
plot_heightinteger, height of the plot canvas
x_labelcharacter, label for the x-axis
y_labelcharacter, label for the y-axis
ylimnumeric vector, limits for the y-axis
xlimnumeric vector, limits for the x-axis
titlecharacter, title of the plot
is_boxplotlogical, whether the plot is a boxplot
draw_legendlogical, whether to draw the legend This function initializes the plot matrix based on the plot canvas.
initialize_plot_matrix()
Initialize the plot matrix
plotcli$initialize_plot_matrix()
plot_widthThe width of the plot
plot_heightThe height of the plot
A plot matrix object
print()
Default print method for plotcli object
plotcli$print(...)
...Additional arguments passed to the print method
The plotcli object, invisibly
add_row()
Add a single row to the plot matrix
plotcli$add_row(bottom = FALSE)
bottomlogical, if TRUE, add row to the bottom of the matrix, otherwise add to the top (default: FALSE)
add_col()
Add a single column to the plot matrix
plotcli$add_col()
add_borders()
Add borders to the plot matrix
plotcli$add_borders()
add_row_col_index()
Add row and column index to the plot matrix Add title to the plot matrix
plotcli$add_row_col_index()
add_title()
plotcli$add_title()
titlecharacter, title of the plot Add y-ticks label to the plot matrix
add_y_ticks()
plotcli$add_y_ticks(n_ticks = 5)
n_ticksnumeric, number of ticks Add y-axis label to the plot matrix
add_y_label()
Add a y-axis label to the plot matrix
plotcli$add_y_label(y_label = self$y_label)
y_labelcharacter, the y-axis label to be added Add x-ticks label to the plot matrix
add_x_ticks()
plotcli$add_x_ticks(n_ticks = 5)
n_ticksnumeric, number of ticks Add x-axis label to the plot matrix
add_x_label()
Add x-axis label to the plot matrix
plotcli$add_x_label(x_label = self$x_label)
x_labelx label Add legend to the plot matrix
add_legend()
Add legend to the plot matrix Add data to the object.
plotcli$add_legend()
add_data()
plotcli$add_data(data)
datalist, list with elements: x, y, type, color, braille, name Get minimum and maximum values for x and y
get_min_max()
Calculate the minimum and maximum values for x and y Function to remove out of range data points if xlim and ylim were given
plotcli$get_min_max()
remove_out_of_range_data()
Remove data points that are outside the specified xlim and ylim Draw a scatter plot to the plot canvas.
plotcli$remove_out_of_range_data()
draw_scatter_plot()
Draw a scatter plot of the specified data set on the plot canvas.
plotcli$draw_scatter_plot(set_idx)
set_idxnumeric, the data element index to be drawn Draw a line plot to the plot canvas.
draw_line_plot()
plotcli$draw_line_plot(set_idx)
set_idxnumeric, the data element index to be drawn Draw a barplot to the plot canvas.
draw_barplot()
plotcli$draw_barplot(set_idx)
set_idxnumeric, the data element index to be drawn Draw a barplot to the plot canvas with braille characters.
draw_barplot_braille()
plotcli$draw_barplot_braille(set_idx)
set_idxnumeric, the data element index to be drawn Draw a boxplot to the plot canvas.
draw_boxplot()
plotcli$draw_boxplot(set_idx)
set_idxnumeric, the data element index to be drawn Draw colors to the canvas
draw_colors()
In the draw_ functions we have been keeping track of the locations of the colored matrix elements. These are now being colored. Draw the different plots types from all data elements to the canvas
plotcli$draw_colors()
draw_plot()
This function iterates through all data elements and calls the appropriate draw_ function based on the plot type (scatter, line, boxplot, or barplot). Make plot matrix: assembles all plot elements (canvas + borders + title + axes + legend)
plotcli$draw_plot()
make_plot_matrix()
This function assembles all plot elements (canvas + borders + title + axes + legend) and creates the final plot matrix. Export plot matrix
plotcli$make_plot_matrix()
export_plot_matrix()
This function exports the plot matrix.
plotcli$export_plot_matrix()
The plot matrix. Main plotting function: assembles all plot elements (canvas + borders + title + axes + legend) and prints the plot by 'cat'ing the plot matrix to the console.
print_plot()
This function assembles all plot elements (canvas + borders + title + axes + legend) and prints the final plot by 'cat'ing the plot matrix to the console. Merge two plotcli objects
This method combines the data from two plotcli objects into a single plotcli object. It takes the maximum of the plot_width and plot_height, combines the titles, and sets the xlim and ylim to the minimum and maximum values of both objects.
plotcli$print_plot()
merge()
plotcli$merge(other)
otherA plotcli object to be merged with the current object.
A new plotcli object containing the combined data from both objects.
clone()
The objects of this class are cloneable with this method.
plotcli$clone(deep = FALSE)
deepWhether to make a deep clone.
# Create a new plotcli object plotcli <- plotcli$new() # Add data for a scatter plot plotcli$add_data(list(x = 1:10, y = rnorm(10), type = "scatter", color = "red")) # Print the plot plotcli$print_plot()# Create a new plotcli object plotcli <- plotcli$new() # Add data for a scatter plot plotcli$add_data(list(x = 1:10, y = rnorm(10), type = "scatter", color = "red")) # Print the plot plotcli$print_plot()
Create a bar plot using plotcli. Short alias: pclb.
plotcli_bar( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "barplot", ... )plotcli_bar( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "barplot", ... )
y |
A numeric vector of values |
x |
A vector of categories |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "barplot") |
... |
Additional arguments passed to the plotcli$new() function |
x <- 1:5 y <- c(10, 15, 8, 12, 6) plotcli_bar(x, y)x <- 1:5 y <- c(10, 15, 8, 12, 6) plotcli_bar(x, y)
Create a box plot using plotcli. Short alias: pclbx.
plotcli_box( y, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "boxplot", ... )plotcli_box( y, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "boxplot", ... )
y |
A list of numeric vectors of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "boxplot") |
... |
Additional arguments passed to the plotcli$new() function |
x |
A vector of categories |
y <- rnorm(50, mean = 0) plotcli_box(y)y <- rnorm(50, mean = 0) plotcli_box(y)
Create a density plot using plotcli. Short alias: pcld.
plotcli_density( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Density", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "density", ... )plotcli_density( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Density", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "density", ... )
x |
A numeric vector of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "Density") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "density") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) plotcli_density(x)x <- rnorm(100) plotcli_density(x)
Create a histogram plot using plotcli. Short alias: pclih.
plotcli_histogram( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Frequency", color = NULL, braille = getOption("plotcli.braille", TRUE), bin_width = NULL, ylim = NULL, name = "histogram", ... )plotcli_histogram( x, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "Frequency", color = NULL, braille = getOption("plotcli.braille", TRUE), bin_width = NULL, ylim = NULL, name = "histogram", ... )
x |
A numeric vector of values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "Frequency") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
bin_width |
Width of the bins (default: NULL) |
ylim |
y limits (default: NULL) |
name |
Name of the plot element (default: "histogram") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) plotcli_histogram(x)x <- rnorm(100) plotcli_histogram(x)
Create a line plot using plotcli. Short alias: pcli.
plotcli_line( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "line", ... )plotcli_line( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "line", ... )
y |
A numeric vector of y values |
x |
A numeric vector of x values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "line") |
... |
Additional arguments passed to the plotcli$new() function |
x <- 1:10 y <- x^2 plotcli_line(x, y)x <- 1:10 y <- x^2 plotcli_line(x, y)
Set global options for plotcli
plotcli_options(plot_width = 60, plot_height = 20, braille = FALSE)plotcli_options(plot_width = 60, plot_height = 20, braille = FALSE)
plot_width |
Default plot width (default: 60) |
plot_height |
Default plot height (default: 20) |
braille |
Default braille setting (default: FALSE) |
Create a scatter plot using plotcli. Short alias: pclis.
plotcli_scatter( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "scatter", ... )plotcli_scatter( y, x = NULL, plot_width = getOption("plotcli.plot_width", 80), plot_height = getOption("plotcli.plot_height", 40), x_label = "x", y_label = "y", color = NULL, braille = getOption("plotcli.braille", TRUE), name = "scatter", ... )
y |
A numeric vector of y values |
x |
A numeric vector of x values |
plot_width |
Width of the plot (default: 80) |
plot_height |
Height of the plot (default: 40) |
x_label |
Label for the x-axis (default: "x") |
y_label |
Label for the y-axis (default: "y") |
color |
Color of the plot elements (default: NULL) |
braille |
Use Braille characters for the plot (default: TRUE) |
name |
Name of the plot element (default: "scatter") |
... |
Additional arguments passed to the plotcli$new() function |
x <- rnorm(100) y <- rnorm(100) plotcli_scatter(x, y)x <- rnorm(100) y <- rnorm(100) plotcli_scatter(x, y)
This function combines multiple plot matrices vertically, centering them horizontally.
rbind_plots(...)rbind_plots(...)
... |
A list of plot matrices to be combined. |
A combined plot matrix.
Generic function for combining plotcli objects vertically
## S3 method for class 'plotcli' rbind(..., deparse.level = 1)## S3 method for class 'plotcli' rbind(..., deparse.level = 1)
... |
plotcli objects to be combined. |
deparse.level |
The deparsing level for the arguments. |
A combined plot matrix.
Register a function that can render a specific ggplot2 geom to a canvas.
register_geom(geom_name, handler)register_geom(geom_name, handler)
geom_name |
Name of the geom (e.g., "GeomPoint", "GeomLine") |
handler |
Function that takes (data, canvas, scales, params) and draws to canvas |
register_geom("GeomPoint", function(data, canvas, scales, params) { # Draw points on canvas })register_geom("GeomPoint", function(data, canvas, scales, params) { # Draw points on canvas })
This function removes ANSI color codes from a given text string.
remove_color_codes(s)remove_color_codes(s)
s |
The text string containing ANSI color codes. |
A text string with ANSI color codes removed.
colored_text <- make_colored("Hello, world!", "blue") remove_color_codes(colored_text)colored_text <- make_colored("Hello, world!", "blue") remove_color_codes(colored_text)