diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..d70aedf Binary files /dev/null and b/.DS_Store differ diff --git a/.Rbuildignore b/.Rbuildignore index 5d4b1be..b647645 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,18 @@ ^\.github$ ^\.gitignore$ -^docs$ \ No newline at end of file +^docs$ +^\.lib$ +^\.DS_Store$ +^tools$ +^plotcli\.Rcheck$ +^plotcli_.*\.tar\.gz$ +^LICENSE$ +^demo_show\.R$ +^mega_show\.R$ +^ultimate_show\.R$ +^ultra_demo\.R$ +^reproduce_.*$ +^vignettes_test\.R$ +^visual_verification\..*$ +^plotcli_docs\.Rmd$ +^\.claude$ diff --git a/DESCRIPTION b/DESCRIPTION index 33f87c7..1d087f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,20 +1,25 @@ Package: plotcli Title: Command Line Interface Plotting -Version: 0.1.0 -Date: 2024-04-01 +Version: 0.3.0 +Date: 2026-02-08 Authors@R: c(person("Claas", "Heuer", role = c("aut", "cre"), email = "claasheuer@gmail.com")) Description: The 'plotcli' package provides terminal-based plotting in R. - It supports colored scatter plots, line plots, bar plots, and box plots. The package allows users - to customize plot appearance, add titles, labels, ticks, and legends, and output the plot as a text-based visualization. + 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. License: LGPL-3 URL: https://github.com/cheuerde/plotcli Encoding: UTF-8 -LazyData: true VignetteBuilder: knitr Depends: R6, ggplot2 -Imports: utils, crayon, knitr, rmarkdown, stringr, rlang +Imports: crayon, stringr, rlang, grDevices, stats Suggests: - testthat (>= 3.0.0) -NeedsCompilation: yes -RoxygenNote: 7.2.3 + testthat (>= 3.0.0), + knitr, + rmarkdown +NeedsCompilation: no +RoxygenNote: 7.3.2 Config/testthat/edition: 3 diff --git a/LICENSE b/LICENSE deleted file mode 100755 index 57de0db..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Claas Heuer - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/NAMESPACE b/NAMESPACE index 39ba9f9..52eb90d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,14 +3,27 @@ S3method("+",plotcli) S3method(cbind,plotcli) S3method(rbind,plotcli) +export(AsciiCanvas) +export(BlockCanvas) +export(BrailleCanvas) +export(Canvas) +export(braille_dot_bit) +export(braille_set_dot) export(bresenham) export(cat_plot_matrix) export(cbind_plots) +export(color_to_term) +export(create_canvas) +export(create_scales) export(format_four_chars) export(get_data_subset) +export(get_geom_handler) export(get_term_colors) export(ggplotcli) +export(init_color_mapping) export(is_braille) +export(is_geom_registered) +export(list_registered_geoms) export(make_colored) export(make_unique_names) export(normalize_data) @@ -20,6 +33,7 @@ export(pclid) export(pclih) export(pclil) export(pclis) +export(pixel_to_braille) export(plotcli) export(plotcli_bar) export(plotcli_box) @@ -29,11 +43,18 @@ export(plotcli_line) export(plotcli_options) export(plotcli_scatter) export(rbind_plots) +export(register_geom) export(remove_color_codes) -import(ggplot2) import(R6) -importFrom("stats", "density") -importFrom(crayon, blue, red, green, yellow, magenta, cyan, silver) -importFrom(knitr, opts_chunk) -importFrom(rmarkdown, html_vignette) -importFrom(utils, head, tail, capture.output) \ No newline at end of file +import(ggplot2) +importFrom(crayon,black) +importFrom(crayon,blue) +importFrom(crayon,cyan) +importFrom(crayon,green) +importFrom(crayon,magenta) +importFrom(crayon,red) +importFrom(crayon,silver) +importFrom(crayon,white) +importFrom(crayon,yellow) +importFrom(grDevices,col2rgb) +importFrom(stats,density) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..be595d1 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,112 @@ +# plotcli 0.3.0 + +## New Geom Handlers + +* **11 new geom handlers** bringing total support from 16 to 27 geoms: + `geom_step`, `geom_abline`, `geom_ribbon`, `geom_errorbar`, + `geom_linerange`, `geom_pointrange`, `geom_crossbar`, `geom_rug`, + `geom_label`, `geom_raster`, `geom_violin` + +* **Violin plots**: Proper mirrored density rendering using `violinwidth` + for accurate shape computation + +## Bug Fixes + +* Fixed division by zero when plotting constant data values + (e.g., all y-values identical) - both root cause fix in `get_min_max()` + and defensive guard in `normalize_data()` (Closes #1) + +--- + +# plotcli 0.2.0 + +## Major New Features + +### Enhanced ggplotcli: Universal ggplot2 Converter + +The `ggplotcli()` function has been completely rewritten to render any ggplot2 +plot in the terminal: + +* **16 Supported Geoms**: `geom_point`, `geom_line`, `geom_path`, `geom_bar`, + `geom_col`, `geom_histogram`, `geom_density`, `geom_smooth`, `geom_area`, + `geom_segment`, `geom_hline`, `geom_vline`, `geom_rect`, `geom_text`, + `geom_boxplot`, `geom_tile` + +* **Legend Support**: Automatic legends for color and fill aesthetics + +* **Faceting Support**: Both `facet_wrap()` and `facet_grid()` work automatically + +* **Theme Auto-Detection**: Automatically respects ggplot2 themes - `theme_bw()` + adds borders and grids, `theme_classic()` shows only borders, etc. + +* **Multiple Canvas Types**: + - `braille`: Highest resolution using Unicode Braille patterns (2x4 dots per character) + - `block`: Medium resolution using block elements + - `ascii`: Basic ASCII characters for maximum compatibility + +* **Styling Options**: Configurable borders, grid lines, titles, subtitles, + captions, and axis labels + +### Boxplot Rendering + +* New `boxplot_style` parameter: `"ascii"` (box-drawing characters) or `"braille"` +* Renders whiskers, box (Q1-Q3), median line, and outliers +* Perfect centering of whiskers and outliers + +### Optimized Color Mapping + +* Intelligent color assignment minimizes repetition across groups +* 6 groups get 6 distinct terminal colors +* 8+ groups use all available colors before repeating +* Colors sorted by hue for visual consistency + +### Canvas Abstraction Layer + +New R6-based canvas system providing: + +* Pixel-level drawing primitives (points, lines, rectangles, circles, polygons) +* Automatic Braille character composition for smooth curves +* Support for colored output via ANSI escape codes + +### Geom Registry + +Extensible system for adding custom geom handlers, making it easy to add +support for additional ggplot2 geoms. + +### Heatmap Support + +* New `geom_tile` handler for rendering heatmaps +* Works with continuous color scales (`scale_fill_gradient`, `scale_fill_viridis_c`, etc.) +* Supports faceted heatmaps with `facet_wrap()` and `facet_grid()` + +## Improvements + +* Improved Braille bit mapping for more accurate scatter and line plots +* Better color handling for multi-group aesthetics +* Fixed issues with quosure parsing in aesthetic mappings +* Fixed axis label formatting (0 now displays as "0", not "0.0e+0") +* Fixed border overlap issue - data no longer appears on/within borders +* Fixed is_braille error with ANSI color codes + +## Bug Fixes (Latest) + +* Fixed `geom_density` not showing distinct colors when using `fill` aesthetic +* Fixed heatmap legend colors not matching plot colors (legend colors now included + in color mapping for consistency) +* Fixed colors not appearing in non-interactive R sessions (Rscript) by enabling + crayon colors automatically on package load +* Fixed discrete x-axis labels showing numeric positions instead of category names + +## Documentation + +* Comprehensive vignette: "ggplotcli: Universal ggplot2 to Terminal Plotting" +* Showcase examples demonstrating maximum complexity plots + +--- + +# plotcli 0.1.0 + +* Initial CRAN release +* Basic terminal plotting with `plotcli` R6 class +* Support for scatter, line, bar, and box plots +* Basic `ggplotcli()` function for ggplot2 conversion diff --git a/R/canvas.r b/R/canvas.r index cc068bf..7ee47a7 100644 --- a/R/canvas.r +++ b/R/canvas.r @@ -395,17 +395,14 @@ AsciiCanvas <- R6Class("AsciiCanvas", #' High-resolution canvas using Unicode Braille patterns. #' Resolution: 2x4 (2 horizontal, 4 vertical dots per character = 8x resolution) #' -#' Braille dot layout: -#' 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│ -#' └────┴────┘ └────┴────┘ +#' Braille dot layout (dot numbers and bit values): +#' \preformatted{ +#' 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 +#' } #' #' @export BrailleCanvas <- R6Class("BrailleCanvas", @@ -490,7 +487,7 @@ BrailleCanvas <- R6Class("BrailleCanvas", #' Block Canvas Class #' #' Canvas using Unicode block elements for 2x vertical resolution. -#' Uses half-block characters: ▀ (upper), ▄ (lower), █ (full) +#' 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) #' diff --git a/R/geom_registry.r b/R/geom_registry.r index 4676574..3f090cb 100644 --- a/R/geom_registry.r +++ b/R/geom_registry.r @@ -4,6 +4,10 @@ #' a dispatch system for converting ggplot2 geoms to terminal plots. #' #' @name GeomRegistry +#' @importFrom grDevices col2rgb +#' @importFrom stats density +#' @import R6 +#' @import ggplot2 NULL #' Geom Registry Environment @@ -73,42 +77,115 @@ is_geom_registered <- function(geom_name) { #' @param built Result from ggplot_build() #' @param plot_width Canvas pixel width #' @param plot_height Canvas pixel height +#' @param has_border Whether a border will be drawn (adds padding) #' @return List with x_scale and y_scale functions #' @export -create_scales <- function(built, plot_width, plot_height) { +create_scales <- function(built, plot_width, plot_height, has_border = FALSE, + x_mult = 1, y_mult = 1) { # Get the panel parameters (contains scale ranges) layout <- built$layout panel_params <- layout$panel_params[[1]] - + # X scale x_range <- panel_params$x.range if (is.null(x_range)) { x_range <- range(built$data[[1]]$x, na.rm = TRUE) } - + # Y scale y_range <- panel_params$y.range if (is.null(y_range)) { y_range <- range(built$data[[1]]$y, na.rm = TRUE) } + + # Add padding if border is present to prevent data from overlapping border + # Padding must be at least the canvas multiplier to ensure data stays in + # a different character cell than the border (e.g., braille is 2x4 per char) + if (has_border) { + x_padding <- x_mult + 1 # Move past border character cell + y_padding <- y_mult + 1 + } else { + x_padding <- 0 + y_padding <- 0 + } + x_min <- 1 + x_padding + x_max <- plot_width - x_padding + y_min <- 1 + y_padding + y_max <- plot_height - y_padding + + # Ensure we have valid ranges + if (x_max <= x_min) { + x_min <- 1 + x_max <- plot_width + } + if (y_max <= y_min) { + y_min <- 1 + y_max <- plot_height + } # Create scaling functions x_scale <- function(x) { - ((x - x_range[1]) / (x_range[2] - x_range[1])) * (plot_width - 1) + 1 + ((x - x_range[1]) / (x_range[2] - x_range[1])) * (x_max - x_min) + x_min } y_scale <- function(y) { # Invert Y because canvas has origin at top-left - plot_height - ((y - y_range[1]) / (y_range[2] - y_range[1])) * (plot_height - 1) + y_max - ((y - y_range[1]) / (y_range[2] - y_range[1])) * (y_max - y_min) } + # Check for discrete x-axis labels (only use for discrete scales) + x_labels <- NULL + x_label_positions <- NULL + x_is_discrete <- !is.null(panel_params$x) && + !is.null(panel_params$x$is_discrete) && + tryCatch(panel_params$x$is_discrete(), error = function(e) FALSE) + + if (x_is_discrete && !is.null(panel_params$x$breaks)) { + x_labels <- panel_params$x$get_labels() + x_label_positions <- attr(panel_params$x$breaks, "pos") + if (is.null(x_label_positions)) { + x_label_positions <- seq_along(x_labels) + } + # Filter out NA values + if (!is.null(x_labels) && length(x_labels) > 0) { + valid <- !is.na(x_labels) + x_labels <- x_labels[valid] + x_label_positions <- x_label_positions[valid] + } + } + + # Check for discrete y-axis labels (only use for discrete scales) + y_labels <- NULL + y_label_positions <- NULL + y_is_discrete <- !is.null(panel_params$y) && + !is.null(panel_params$y$is_discrete) && + tryCatch(panel_params$y$is_discrete(), error = function(e) FALSE) + + if (y_is_discrete && !is.null(panel_params$y$breaks)) { + y_labels <- panel_params$y$get_labels() + y_label_positions <- attr(panel_params$y$breaks, "pos") + if (is.null(y_label_positions)) { + y_label_positions <- seq_along(y_labels) + } + # Filter out NA values + if (!is.null(y_labels) && length(y_labels) > 0) { + valid <- !is.na(y_labels) + y_labels <- y_labels[valid] + y_label_positions <- y_label_positions[valid] + } + } + list( x = x_scale, y = y_scale, x_range = x_range, y_range = y_range, width = plot_width, - height = plot_height + height = plot_height, + x_labels = x_labels, + x_label_positions = x_label_positions, + y_labels = y_labels, + y_label_positions = y_label_positions ) } @@ -121,7 +198,7 @@ create_scales <- function(built, plot_width, plot_height) { #' #' Renders points as individual pixels or small shapes #' @keywords internal -geom_point_handler <- function(data, canvas, scales, params) { +geom_point_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Get color mapping colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) @@ -146,7 +223,7 @@ geom_point_handler <- function(data, canvas, scales, params) { #' #' Renders connected lines #' @keywords internal -geom_line_handler <- function(data, canvas, scales, params) { +geom_line_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Sort by x to ensure proper line connections data <- data[order(data$x), ] @@ -182,7 +259,7 @@ geom_line_handler <- function(data, canvas, scales, params) { #' #' Renders connected paths (order by data, not x) #' @keywords internal -geom_path_handler <- function(data, canvas, scales, params) { +geom_path_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Group by colour/group if present if ("group" %in% names(data)) { groups <- unique(data$group) @@ -215,7 +292,7 @@ geom_path_handler <- function(data, canvas, scales, params) { #' #' Renders bar charts #' @keywords internal -geom_bar_handler <- function(data, canvas, scales, params) { +geom_bar_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Get colors colors <- if ("fill" %in% names(data)) data$fill else rep("white", nrow(data)) @@ -243,7 +320,7 @@ geom_bar_handler <- function(data, canvas, scales, params) { #' #' Renders filled areas #' @keywords internal -geom_area_handler <- function(data, canvas, scales, params) { +geom_area_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Sort by x data <- data[order(data$x), ] @@ -266,7 +343,7 @@ geom_area_handler <- function(data, canvas, scales, params) { #' #' Renders line segments #' @keywords internal -geom_segment_handler <- function(data, canvas, scales, params) { +geom_segment_handler <- function(data, canvas, scales, params, style_opts = NULL) { colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) for (i in seq_len(nrow(data))) { @@ -290,7 +367,7 @@ geom_segment_handler <- function(data, canvas, scales, params) { #' #' Renders horizontal lines #' @keywords internal -geom_hline_handler <- function(data, canvas, scales, params) { +geom_hline_handler <- function(data, canvas, scales, params, style_opts = NULL) { colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) for (i in seq_len(nrow(data))) { @@ -311,7 +388,7 @@ geom_hline_handler <- function(data, canvas, scales, params) { #' #' Renders vertical lines #' @keywords internal -geom_vline_handler <- function(data, canvas, scales, params) { +geom_vline_handler <- function(data, canvas, scales, params, style_opts = NULL) { colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) for (i in seq_len(nrow(data))) { @@ -332,7 +409,7 @@ geom_vline_handler <- function(data, canvas, scales, params) { #' #' Renders rectangles #' @keywords internal -geom_rect_handler <- function(data, canvas, scales, params) { +geom_rect_handler <- function(data, canvas, scales, params, style_opts = NULL) { colors <- if ("fill" %in% names(data)) data$fill else rep("white", nrow(data)) for (i in seq_len(nrow(data))) { @@ -357,7 +434,7 @@ geom_rect_handler <- function(data, canvas, scales, params) { #' #' Renders smoothed lines (just draws the line, ignores confidence interval) #' @keywords internal -geom_smooth_handler <- function(data, canvas, scales, params) { +geom_smooth_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Sort by x data <- data[order(data$x), ] @@ -380,7 +457,7 @@ geom_smooth_handler <- function(data, canvas, scales, params) { #' #' Renders density curves #' @keywords internal -geom_density_handler <- function(data, canvas, scales, params) { +geom_density_handler <- function(data, canvas, scales, params, style_opts = NULL) { # Group by group if present if ("group" %in% names(data)) { groups <- unique(data$group) @@ -395,13 +472,20 @@ geom_density_handler <- function(data, canvas, scales, params) { if (nrow(grp_data) < 2) next - # Get color - color <- if ("colour" %in% names(grp_data)) { + # Get color - prefer fill over colour for density plots + # (density plots typically use fill aesthetic for distinction) + color <- if ("fill" %in% names(grp_data) && + !is.na(grp_data$fill[1]) && + grp_data$fill[1] != "grey20") { + color_to_term(grp_data$fill[1]) + } else if ("colour" %in% names(grp_data) && + !is.na(grp_data$colour[1]) && + grp_data$colour[1] != "black") { color_to_term(grp_data$colour[1]) } else { NULL } - + # Use density as y xs <- sapply(grp_data$x, scales$x) ys <- sapply(grp_data$density, scales$y) @@ -418,11 +502,237 @@ geom_density_handler <- function(data, canvas, scales, params) { geom_histogram_handler <- geom_bar_handler +#' GeomBoxplot Handler +#' +#' Renders boxplots with whiskers, box, median line, and outliers. +#' Supports two styles: "ascii" (box-drawing characters) and "braille" (Braille dots). +#' @keywords internal +geom_boxplot_handler <- function(data, canvas, scales, params, style_opts = NULL) { + # Get boxplot style (default to "ascii" for classic look) + boxplot_style <- if (!is.null(style_opts) && !is.null(style_opts$boxplot_style)) { + style_opts$boxplot_style + } else { + "ascii" + } + + # Get colors + fill_colors <- if ("fill" %in% names(data)) data$fill else rep("white", nrow(data)) + outline_colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + # Get boxplot statistics + x <- data$x[i] + xmin <- data$xmin[i] + xmax <- data$xmax[i] + ymin <- data$ymin[i] # Lower whisker + lower <- data$lower[i] # Q1 + middle <- data$middle[i] # Median + upper <- data$upper[i] # Q3 + ymax <- data$ymax[i] # Upper whisker + outliers <- data$outliers[[i]] + + # Get color + fill_color <- fill_colors[i] + if (!is.null(fill_color) && !is.na(fill_color)) { + fill_color <- color_to_term(fill_color) + } else { + fill_color <- NULL + } + + outline_color <- outline_colors[i] + if (!is.null(outline_color) && !is.na(outline_color)) { + outline_color <- color_to_term(outline_color) + } else { + outline_color <- fill_color + } + + # Scale coordinates + sx <- scales$x(x) + sxmin <- scales$x(xmin) + sxmax <- scales$x(xmax) + symin <- scales$y(ymin) + slower <- scales$y(lower) + smiddle <- scales$y(middle) + supper <- scales$y(upper) + symax <- scales$y(ymax) + + if (boxplot_style == "ascii") { + # ASCII style: use box-drawing characters directly on the character grid + # Convert pixel coordinates to character coordinates + # Use the center x coordinate as the reference point + char_x <- round(sx / canvas$x_mult) + char_ymin <- round(symin / canvas$y_mult) + char_lower <- round(slower / canvas$y_mult) + char_middle <- round(smiddle / canvas$y_mult) + char_upper <- round(supper / canvas$y_mult) + char_ymax <- round(symax / canvas$y_mult) + + # Calculate box width in character units from the data + box_half_width <- round((sxmax - sxmin) / canvas$x_mult / 2) + if (box_half_width < 2) box_half_width <- 2 # Minimum width for visible box + + # Box-drawing characters + horiz <- "\u2500" # horizontal line + vert <- "\u2502" # vertical line + top_left <- "\u250c" # top left corner + top_right <- "\u2510" # top right corner + bottom_left <- "\u2514" # bottom left corner + bottom_right <- "\u2518" # bottom right corner + + # Get canvas matrix dimensions + n_rows <- nrow(canvas$matrix) + n_cols <- ncol(canvas$matrix) + + # Clamp center to valid range + char_x <- max(1, min(n_cols, char_x)) + char_ymin <- max(1, min(n_rows, char_ymin)) + char_lower <- max(1, min(n_rows, char_lower)) + char_middle <- max(1, min(n_rows, char_middle)) + char_upper <- max(1, min(n_rows, char_upper)) + char_ymax <- max(1, min(n_rows, char_ymax)) + + # Calculate box boundaries from center + box_left <- max(1, char_x - box_half_width) + box_right <- min(n_cols, char_x + box_half_width) + box_top <- min(char_lower, char_upper) + box_bottom <- max(char_lower, char_upper) + + # Draw whiskers (vertical lines) - use char_x (true center from data) + # Only draw whiskers OUTSIDE the box (between ymin and lower, between upper and ymax) + # Lower whisker: from ymin to just before lower (box_bottom) + if (char_ymin != box_bottom) { + whisker_rows_lower <- seq(min(box_bottom, char_ymin), max(box_bottom, char_ymin)) + # Exclude the box edge itself + whisker_rows_lower <- whisker_rows_lower[whisker_rows_lower != box_bottom] + for (row in whisker_rows_lower) { + if (row >= 1 && row <= n_rows && char_x >= 1 && char_x <= n_cols) { + canvas$matrix[row, char_x] <- make_colored(vert, fill_color) + } + } + } + # Upper whisker: from just after upper (box_top) to ymax + if (char_ymax != box_top) { + whisker_rows_upper <- seq(min(box_top, char_ymax), max(box_top, char_ymax)) + # Exclude the box edge itself + whisker_rows_upper <- whisker_rows_upper[whisker_rows_upper != box_top] + for (row in whisker_rows_upper) { + if (row >= 1 && row <= n_rows && char_x >= 1 && char_x <= n_cols) { + canvas$matrix[row, char_x] <- make_colored(vert, fill_color) + } + } + } + + # Draw whisker caps (horizontal lines) - same width as median (inside box) + # Only draw caps if they differ from the box edges + for (col in (box_left + 1):(box_right - 1)) { + if (col >= 1 && col <= n_cols) { + if (char_ymin >= 1 && char_ymin <= n_rows && char_ymin != box_bottom) { + canvas$matrix[char_ymin, col] <- make_colored(horiz, fill_color) + } + if (char_ymax >= 1 && char_ymax <= n_rows && char_ymax != box_top) { + canvas$matrix[char_ymax, col] <- make_colored(horiz, fill_color) + } + } + } + + # Top and bottom of box + for (col in box_left:box_right) { + if (box_top >= 1 && box_top <= n_rows) { + canvas$matrix[box_top, col] <- make_colored(horiz, fill_color) + } + if (box_bottom >= 1 && box_bottom <= n_rows) { + canvas$matrix[box_bottom, col] <- make_colored(horiz, fill_color) + } + } + + # Sides of box + for (row in box_top:box_bottom) { + if (row >= 1 && row <= n_rows) { + if (box_left >= 1 && box_left <= n_cols) { + canvas$matrix[row, box_left] <- make_colored(vert, fill_color) + } + if (box_right >= 1 && box_right <= n_cols) { + canvas$matrix[row, box_right] <- make_colored(vert, fill_color) + } + } + } + + # Corners + if (box_top >= 1 && box_top <= n_rows) { + if (box_left >= 1 && box_left <= n_cols) { + canvas$matrix[box_top, box_left] <- make_colored(top_left, fill_color) + } + if (box_right >= 1 && box_right <= n_cols) { + canvas$matrix[box_top, box_right] <- make_colored(top_right, fill_color) + } + } + if (box_bottom >= 1 && box_bottom <= n_rows) { + if (box_left >= 1 && box_left <= n_cols) { + canvas$matrix[box_bottom, box_left] <- make_colored(bottom_left, fill_color) + } + if (box_right >= 1 && box_right <= n_cols) { + canvas$matrix[box_bottom, box_right] <- make_colored(bottom_right, fill_color) + } + } + + # Median line - only inside the box (not including the border) + if (char_middle >= 1 && char_middle <= n_rows) { + for (col in (box_left + 1):(box_right - 1)) { + if (col >= 1 && col <= n_cols) { + canvas$matrix[char_middle, col] <- make_colored(horiz, fill_color) + } + } + } + + # Outliers - use char_x (true center from data) + if (length(outliers) > 0 && !all(is.na(outliers))) { + for (out in outliers) { + if (!is.na(out)) { + char_y_out <- round(scales$y(out) / canvas$y_mult) + if (char_y_out >= 1 && char_y_out <= n_rows && + char_x >= 1 && char_x <= n_cols) { + canvas$matrix[char_y_out, char_x] <- make_colored("*", fill_color) + } + } + } + } + + } else { + # Braille style: use canvas drawing methods (high resolution) + # Draw whiskers (vertical lines from box to whisker ends) + canvas$draw_segment(round(sx), round(slower), round(sx), round(symin), color = fill_color) + canvas$draw_segment(round(sx), round(supper), round(sx), round(symax), color = fill_color) + + # Draw whisker caps (horizontal lines at whisker ends) + cap_width <- (sxmax - sxmin) / 2 + canvas$draw_segment(round(sx - cap_width/2), round(symin), round(sx + cap_width/2), round(symin), color = fill_color) + canvas$draw_segment(round(sx - cap_width/2), round(symax), round(sx + cap_width/2), round(symax), color = fill_color) + + # Draw box (rectangle from Q1 to Q3) + canvas$draw_rect(round(sxmin), round(supper), round(sxmax), round(slower), color = fill_color) + + # Draw median line + canvas$draw_segment(round(sxmin), round(smiddle), round(sxmax), round(smiddle), color = fill_color) + + # Draw outliers + if (length(outliers) > 0 && !all(is.na(outliers))) { + for (out in outliers) { + if (!is.na(out)) { + sy_out <- scales$y(out) + canvas$set_pixel(round(sx), round(sy_out), fill_color) + } + } + } + } + } +} + + #' GeomText Handler #' #' Renders text labels #' @keywords internal -geom_text_handler <- function(data, canvas, scales, params) { +geom_text_handler <- function(data, canvas, scales, params, style_opts = NULL) { colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) for (i in seq_len(nrow(data))) { @@ -450,8 +760,108 @@ geom_text_handler <- function(data, canvas, scales, params) { # Color Conversion # ============================================================================ +# ============================================================================ +# Color Mapping System +# ============================================================================ + +# Environment to store color mappings for the current plot +.color_map_env <- new.env(parent = emptyenv()) + +#' Initialize color mapping for a set of ggplot colors +#' +#' This function takes all unique colors from a ggplot and assigns terminal +#' colors to minimize repetition while respecting hue similarity. +#' +#' @param ggplot_colors Vector of unique colors from ggplot +#' @export +init_color_mapping <- function(ggplot_colors) { + # Available chromatic terminal colors (in hue order: 0, 60, 120, 180, 240, 300) + term_colors <- c("red", "yellow", "green", "cyan", "blue", "magenta") + n_term <- length(term_colors) + + # Filter out NULL/NA and get unique colors + ggplot_colors <- unique(ggplot_colors[!is.na(ggplot_colors) & !is.null(ggplot_colors)]) + n_colors <- length(ggplot_colors) + + if (n_colors == 0) { + .color_map_env$mapping <- list() + return(invisible(NULL)) + } + + # Calculate hue for each ggplot color + hues <- sapply(ggplot_colors, get_color_hue) + + # Sort colors by hue + hue_order <- order(hues) + sorted_colors <- ggplot_colors[hue_order] + sorted_hues <- hues[hue_order] + + # Assign terminal colors to minimize repetition + # Strategy: distribute terminal colors evenly across the sorted hue spectrum + mapping <- list() + + if (n_colors <= n_term) { + # We have enough terminal colors - assign each ggplot color a unique one + # Use the hue-sorted order to assign colors that are spread out + term_indices <- round(seq(1, n_term, length.out = n_colors)) + for (i in seq_along(sorted_colors)) { + mapping[[sorted_colors[i]]] <- term_colors[term_indices[i]] + } + } else { + # More ggplot colors than terminal colors - minimize repetition + # Each terminal color will be used ceiling(n_colors/n_term) or floor times + # Distribute evenly across the hue-sorted colors + for (i in seq_along(sorted_colors)) { + # Cycle through terminal colors + term_idx <- ((i - 1) %% n_term) + 1 + mapping[[sorted_colors[i]]] <- term_colors[term_idx] + } + } + + .color_map_env$mapping <- mapping + invisible(NULL) +} + +#' Get the hue of a color (0-360 degrees) +#' +#' @param color A color value +#' @return Hue in degrees (0-360) or NA for grayscale +#' @keywords internal +get_color_hue <- function(color) { + if (is.null(color) || is.na(color)) return(NA) + + tryCatch({ + rgb_val <- col2rgb(color) + r <- rgb_val[1, 1] + g <- rgb_val[2, 1] + b <- rgb_val[3, 1] + + max_val <- max(r, g, b) + min_val <- min(r, g, b) + chroma <- max_val - min_val + + if (chroma == 0) return(NA) # Grayscale + + if (max_val == r) { + hue <- 60 * (((g - b) / chroma) %% 6) + } else if (max_val == g) { + hue <- 60 * ((b - r) / chroma + 2) + } else { + hue <- 60 * ((r - g) / chroma + 4) + } + + if (hue < 0) hue <- hue + 360 + return(hue) + }, error = function(e) { + return(NA) + }) +} + #' Convert ggplot2 color to terminal color name #' +#' If init_color_mapping() was called, uses the pre-computed mapping. +#' Otherwise falls back to simple hue-based matching. +#' #' @param color A color value (hex, name, or R color) #' @return A terminal color name (blue, red, green, etc.) or NULL #' @export @@ -464,40 +874,51 @@ color_to_term <- function(color) { return(tolower(color)) } - # Try to convert hex/named color to RGB and find closest terminal color + # Check if we have a pre-computed mapping + if (exists("mapping", envir = .color_map_env) && + length(.color_map_env$mapping) > 0 && + color %in% names(.color_map_env$mapping)) { + return(.color_map_env$mapping[[color]]) + } + + # Fallback: simple hue-based matching tryCatch({ - rgb <- col2rgb(color) - r <- rgb[1, 1] - g <- rgb[2, 1] - b <- rgb[3, 1] + rgb_val <- col2rgb(color) + r <- rgb_val[1, 1] + g <- rgb_val[2, 1] + b <- rgb_val[3, 1] - # Simple heuristic: find dominant channel + # Check for near-black or near-white first max_val <- max(r, g, b) min_val <- min(r, g, b) - if (max_val < 50) return("black") - if (min_val > 200) return("white") + if (max_val < 40) return("black") + if (min_val > 220) return("white") - # Check for grayscale - if (max_val - min_val < 30) { - if (max_val > 180) return("white") - if (max_val > 100) return("silver") + # Check for grayscale (low saturation) + if (max_val - min_val < 25) { + if (max_val > 170) return("white") + if (max_val > 85) return("silver") return("black") } - # Find dominant color - if (r >= g && r >= b) { - if (g > b && g > 100) return("yellow") - if (b > g && b > 100) return("magenta") + # Get hue and map to terminal color + hue <- get_color_hue(color) + if (is.na(hue)) return("silver") + + # Map hue to terminal colors (60-degree segments) + if (hue < 30 || hue >= 330) { return("red") - } else if (g >= r && g >= b) { - if (r > b && r > 100) return("yellow") - if (b > r && b > 100) return("cyan") + } else if (hue < 90) { + return("yellow") + } else if (hue < 150) { return("green") - } else { - if (r > g && r > 100) return("magenta") - if (g > r && g > 100) return("cyan") + } else if (hue < 210) { + return("cyan") + } else if (hue < 270) { return("blue") + } else { + return("magenta") } }, error = function(e) { return(NULL) @@ -505,6 +926,417 @@ color_to_term <- function(color) { } +#' GeomTile Handler +#' +#' Renders tiles/heatmaps. Tiles use center (x, y) coordinates with width/height. +#' @keywords internal +geom_tile_handler <- function(data, canvas, scales, params, style_opts = NULL) { + # Get fill colors + colors <- if ("fill" %in% names(data)) data$fill else rep("white", nrow(data)) + + # Default tile dimensions (usually 1 for discrete scales) + default_width <- if ("width" %in% names(data) && !is.na(data$width[1])) data$width[1] else 1 + default_height <- if ("height" %in% names(data) && !is.na(data$height[1])) data$height[1] else 1 + + for (i in seq_len(nrow(data))) { + # Get center coordinates - skip if NA + x_center <- data$x[i] + y_center <- data$y[i] + if (is.na(x_center) || is.na(y_center)) next + + # Get tile dimensions + tile_width <- if ("width" %in% names(data) && !is.na(data$width[i])) { + data$width[i] + } else { + default_width + } + tile_height <- if ("height" %in% names(data) && !is.na(data$height[i])) { + data$height[i] + } else { + default_height + } + + # Calculate corners from center + xmin <- x_center - tile_width / 2 + xmax <- x_center + tile_width / 2 + ymin <- y_center - tile_height / 2 + ymax <- y_center + tile_height / 2 + + # Scale to canvas coordinates + xmin_scaled <- scales$x(xmin) + xmax_scaled <- scales$x(xmax) + ymin_scaled <- scales$y(ymin) + ymax_scaled <- scales$y(ymax) + + # Check for valid coordinates + if (any(is.na(c(xmin_scaled, xmax_scaled, ymin_scaled, ymax_scaled)))) next + + # Get color + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + # Draw filled rectangle (note: y is inverted in canvas coordinates) + canvas$fill_rect(round(xmin_scaled), round(ymax_scaled), + round(xmax_scaled), round(ymin_scaled), color) + } +} + + +# ============================================================================ +# Additional Geom Handlers +# ============================================================================ + +#' GeomStep Handler +#' +#' Renders step functions (staircase lines) +#' @keywords internal +geom_step_handler <- function(data, canvas, scales, params, style_opts = NULL) { + # Group by group if present + if ("group" %in% names(data)) { + groups <- unique(data$group) + } else { + groups <- 1 + data$group <- 1 + } + + for (grp in groups) { + grp_data <- data[data$group == grp, ] + grp_data <- grp_data[order(grp_data$x), ] + if (nrow(grp_data) < 2) next + + color <- if ("colour" %in% names(grp_data)) { + color_to_term(grp_data$colour[1]) + } else { + NULL + } + + # Build step coordinates: horizontal then vertical + xs <- numeric(0) + ys <- numeric(0) + for (i in seq_len(nrow(grp_data))) { + sx <- scales$x(grp_data$x[i]) + sy <- scales$y(grp_data$y[i]) + if (i > 1) { + # Horizontal segment to new x at previous y + xs <- c(xs, sx) + ys <- c(ys, ys[length(ys)]) + } + xs <- c(xs, sx) + ys <- c(ys, sy) + } + + canvas$draw_polyline(xs, ys, color) + } +} + +#' GeomAbline Handler +#' +#' Renders diagonal reference lines (slope + intercept) +#' @keywords internal +geom_abline_handler <- function(data, canvas, scales, params, style_opts = NULL) { + colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + intercept <- data$intercept[i] + slope <- data$slope[i] + + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + # Compute line endpoints from x_range + x0 <- scales$x_range[1] + x1 <- scales$x_range[2] + y0 <- intercept + slope * x0 + y1 <- intercept + slope * x1 + + # Clamp to y_range + y0 <- max(scales$y_range[1], min(scales$y_range[2], y0)) + y1 <- max(scales$y_range[1], min(scales$y_range[2], y1)) + + canvas$draw_line( + round(scales$x(x0)), round(scales$y(y0)), + round(scales$x(x1)), round(scales$y(y1)), + color + ) + } +} + +#' GeomRibbon Handler +#' +#' Renders filled ribbons between ymin and ymax +#' @keywords internal +geom_ribbon_handler <- function(data, canvas, scales, params, style_opts = NULL) { + if ("group" %in% names(data)) { + groups <- unique(data$group) + } else { + groups <- 1 + data$group <- 1 + } + + for (grp in groups) { + grp_data <- data[data$group == grp, ] + grp_data <- grp_data[order(grp_data$x), ] + if (nrow(grp_data) < 2) next + + color <- if ("fill" %in% names(grp_data)) { + color_to_term(grp_data$fill[1]) + } else if ("colour" %in% names(grp_data)) { + color_to_term(grp_data$colour[1]) + } else { + NULL + } + + # Fill between ymin and ymax by drawing vertical segments + for (i in seq_len(nrow(grp_data))) { + x_px <- round(scales$x(grp_data$x[i])) + ymin_px <- round(scales$y(grp_data$ymin[i])) + ymax_px <- round(scales$y(grp_data$ymax[i])) + # y is inverted: ymax_px < ymin_px in pixel space + top <- min(ymin_px, ymax_px) + bottom <- max(ymin_px, ymax_px) + for (py in top:bottom) { + canvas$set_pixel(x_px, py, color) + } + } + } +} + +#' GeomErrorbar Handler +#' +#' Renders vertical error bars with horizontal caps +#' @keywords internal +geom_errorbar_handler <- function(data, canvas, scales, params, style_opts = NULL) { + colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + x_px <- round(scales$x(data$x[i])) + ymin_px <- round(scales$y(data$ymin[i])) + ymax_px <- round(scales$y(data$ymax[i])) + + # Vertical line + canvas$draw_line(x_px, ymin_px, x_px, ymax_px, color) + + # Horizontal caps using xmin/xmax if available, otherwise approximate + if ("xmin" %in% names(data) && "xmax" %in% names(data)) { + xmin_px <- round(scales$x(data$xmin[i])) + xmax_px <- round(scales$x(data$xmax[i])) + } else { + cap_half <- max(2, round(scales$width * 0.01)) + xmin_px <- x_px - cap_half + xmax_px <- x_px + cap_half + } + + canvas$draw_line(xmin_px, ymin_px, xmax_px, ymin_px, color) + canvas$draw_line(xmin_px, ymax_px, xmax_px, ymax_px, color) + } +} + +#' GeomLinerange Handler +#' +#' Renders vertical line ranges (no caps) +#' @keywords internal +geom_linerange_handler <- function(data, canvas, scales, params, style_opts = NULL) { + colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + x_px <- round(scales$x(data$x[i])) + ymin_px <- round(scales$y(data$ymin[i])) + ymax_px <- round(scales$y(data$ymax[i])) + + canvas$draw_line(x_px, ymin_px, x_px, ymax_px, color) + } +} + +#' GeomPointrange Handler +#' +#' Renders point with vertical line range +#' @keywords internal +geom_pointrange_handler <- function(data, canvas, scales, params, style_opts = NULL) { + colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + x_px <- round(scales$x(data$x[i])) + y_px <- round(scales$y(data$y[i])) + ymin_px <- round(scales$y(data$ymin[i])) + ymax_px <- round(scales$y(data$ymax[i])) + + # Line range + canvas$draw_line(x_px, ymin_px, x_px, ymax_px, color) + # Point at center + canvas$set_pixel(x_px, y_px, color) + } +} + +#' GeomCrossbar Handler +#' +#' Renders crossbar (box with middle line, no whiskers) +#' @keywords internal +geom_crossbar_handler <- function(data, canvas, scales, params, style_opts = NULL) { + fill_colors <- if ("fill" %in% names(data)) data$fill else rep(NA, nrow(data)) + outline_colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + + for (i in seq_len(nrow(data))) { + color <- outline_colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + fill_color <- fill_colors[i] + if (!is.null(fill_color) && !is.na(fill_color)) { + fill_color <- color_to_term(fill_color) + } else { + fill_color <- NULL + } + + xmin_px <- round(scales$x(data$xmin[i])) + xmax_px <- round(scales$x(data$xmax[i])) + y_px <- round(scales$y(data$y[i])) + ymin_px <- round(scales$y(data$ymin[i])) + ymax_px <- round(scales$y(data$ymax[i])) + + # Fill if fill color given + if (!is.null(fill_color)) { + canvas$fill_rect(xmin_px, min(ymin_px, ymax_px), xmax_px, max(ymin_px, ymax_px), fill_color) + } + + # Outline rectangle + canvas$draw_rect(xmin_px, min(ymin_px, ymax_px), xmax_px, max(ymin_px, ymax_px), color) + # Middle line (median) + canvas$draw_line(xmin_px, y_px, xmax_px, y_px, color) + } +} + +#' GeomRug Handler +#' +#' Renders rug marks (short tick marks along axes) +#' @keywords internal +geom_rug_handler <- function(data, canvas, scales, params, style_opts = NULL) { + colors <- if ("colour" %in% names(data)) data$colour else rep("white", nrow(data)) + rug_length <- max(2, round(scales$height * 0.03)) + + for (i in seq_len(nrow(data))) { + color <- colors[i] + if (!is.null(color) && !is.na(color)) { + color <- color_to_term(color) + } else { + color <- NULL + } + + # X rug: short vertical tick at bottom + if ("x" %in% names(data) && !is.na(data$x[i])) { + x_px <- round(scales$x(data$x[i])) + canvas$draw_line(x_px, scales$height, x_px, scales$height - rug_length, color) + } + + # Y rug: short horizontal tick at left + if ("y" %in% names(data) && !is.na(data$y[i])) { + y_px <- round(scales$y(data$y[i])) + canvas$draw_line(1, y_px, 1 + rug_length, y_px, color) + } + } +} + +#' GeomLabel Handler +#' +#' Renders text labels (same as geom_text for terminal) +#' @keywords internal +geom_label_handler <- geom_text_handler + +#' GeomRaster Handler +#' +#' Renders raster images (same as tile for terminal) +#' @keywords internal +geom_raster_handler <- geom_tile_handler + +#' GeomViolin Handler +#' +#' Renders violin plots (mirrored density curves) +#' @keywords internal +geom_violin_handler <- function(data, canvas, scales, params, style_opts = NULL) { + if ("group" %in% names(data)) { + groups <- unique(data$group) + } else { + groups <- 1 + data$group <- 1 + } + + for (grp in groups) { + grp_data <- data[data$group == grp, ] + grp_data <- grp_data[order(grp_data$y), ] + if (nrow(grp_data) < 2) next + + fill_color <- if ("fill" %in% names(grp_data) && !is.na(grp_data$fill[1])) { + color_to_term(grp_data$fill[1]) + } else { + NULL + } + + outline_color <- if ("colour" %in% names(grp_data) && !is.na(grp_data$colour[1])) { + color_to_term(grp_data$colour[1]) + } else { + fill_color + } + + # Compute actual violin edges from violinwidth + # (xmin/xmax in data are group bounds, not the per-slice shape) + x_center <- grp_data$x + vw <- grp_data$violinwidth + xminv <- x_center - vw * (x_center - grp_data$xmin) + xmaxv <- x_center + vw * (grp_data$xmax - x_center) + + # Fill violin body + for (i in seq_len(nrow(grp_data))) { + xmin_px <- round(scales$x(xminv[i])) + xmax_px <- round(scales$x(xmaxv[i])) + y_px <- round(scales$y(grp_data$y[i])) + if (xmin_px <= xmax_px) { + for (px in xmin_px:xmax_px) { + canvas$set_pixel(px, y_px, fill_color) + } + } + } + + # Draw outline polylines for left and right edges + xs_left <- sapply(xminv, scales$x) + xs_right <- sapply(xmaxv, scales$x) + ys <- sapply(grp_data$y, scales$y) + canvas$draw_polyline(xs_left, ys, outline_color) + canvas$draw_polyline(xs_right, ys, outline_color) + } +} + + # ============================================================================ # Register Built-in Geoms # ============================================================================ @@ -520,10 +1352,23 @@ color_to_term <- function(color) { register_geom("GeomHline", geom_hline_handler) register_geom("GeomVline", geom_vline_handler) register_geom("GeomRect", geom_rect_handler) + register_geom("GeomTile", geom_tile_handler) register_geom("GeomSmooth", geom_smooth_handler) register_geom("GeomDensity", geom_density_handler) register_geom("GeomHistogram", geom_histogram_handler) register_geom("GeomText", geom_text_handler) + register_geom("GeomBoxplot", geom_boxplot_handler) + register_geom("GeomStep", geom_step_handler) + register_geom("GeomAbline", geom_abline_handler) + register_geom("GeomRibbon", geom_ribbon_handler) + register_geom("GeomErrorbar", geom_errorbar_handler) + register_geom("GeomLinerange", geom_linerange_handler) + register_geom("GeomPointrange", geom_pointrange_handler) + register_geom("GeomCrossbar", geom_crossbar_handler) + register_geom("GeomRug", geom_rug_handler) + register_geom("GeomLabel", geom_label_handler) + register_geom("GeomRaster", geom_raster_handler) + register_geom("GeomViolin", geom_violin_handler) } # Register geoms when the file is sourced diff --git a/R/ggplotcli.r b/R/ggplotcli.r index ffd850f..0674bdd 100644 --- a/R/ggplotcli.r +++ b/R/ggplotcli.r @@ -26,13 +26,6 @@ get_data_subset <- function(geom_name, data, aes, p_build) { } - #if(geom_name %in% c("GeomBar")) { - - # out$y = data[[rlang::as_name(aes$x)]] - # out$x = rep(1, length(out$y)) - - #} - if(!geom_name %in% c("GeomDensity", "GeomSmooth", "GeomBoxplot", "GeomBar")) { out$x = data[[rlang::as_name(aes$x)]] @@ -50,6 +43,7 @@ get_data_subset <- function(geom_name, data, aes, p_build) { #' #' @param aes_expr The aesthetic expression (can be a quosure) #' @return Character string of the column name, or NULL +#' @keywords internal safe_aes_name <- function(aes_expr) { if (is.null(aes_expr)) return(NULL) @@ -87,99 +81,154 @@ safe_aes_name <- function(aes_expr) { }) } -#' ggplotcli - Render ggplot objects in the terminal +#' ggplotcli - Render ggplot2 objects in the terminal #' -#' This function takes a ggplot object and renders it in the terminal using ASCII or Braille characters. +#' Convert any ggplot2 plot to a terminal-based visualization using Unicode +#' Braille characters or ASCII. Supports 15+ geom types, faceting, themes, +#' and color aesthetics. #' -#' @param ggplot_obj A ggplot object to be rendered in the terminal. -#' @param plot_width Width of the terminal plot in characters (default: 80). -#' @param plot_height Height of the terminal plot in characters (default: 40). -#' @param braille Use Braille characters for higher resolution (default: TRUE). +#' @param p A ggplot2 object to render +#' @param width Character width of the plot (default: 60) +#' @param height Character height of the plot (default: 20) +#' @param canvas_type Type of canvas: "braille" (high-res), "block" (medium), or "ascii" (basic). Default: "braille" +#' @param border Draw border around plot. "auto" uses ggplot theme, or TRUE/FALSE (default: "auto") +#' @param grid Grid lines: "none", "major", "minor", "both", or "auto" (default: "none") +#' @param show_axes Whether to show axis values (default: TRUE) +#' @param axis_labels Whether to show axis labels from ggplot (default: TRUE) +#' @param legend Legend display: "auto", "right", "bottom", "none" (default: "auto") +#' @param title_align Title alignment: "center" or "left" (default: "center") +#' @param subtitle Whether to show subtitle (default: TRUE) +#' @param caption Whether to show caption (default: TRUE) +#' @param title Optional title override (NULL uses ggplot title) +#' @param boxplot_style Style for boxplots: "ascii" uses box-drawing characters (default), +#' "braille" uses Braille dots like other geoms #' -#' @return A TerminalPlot object. +#' @return Invisibly returns the canvas object #' @export -ggplotcli <- function(ggplot_obj, plot_width = 80, plot_height = 40, braille = TRUE) { - - geoms_valid <- data.frame( - geom = c("GeomPoint", "GeomLine", "GeomDensity", "GeomSmooth", "GeomBar", "GeomBoxplot"), - plot_type = c("scatter", "line", "line", "line", "barplot", "boxplot") - ) - - p_build = ggplot2::ggplot_build(ggplot_obj) - - data <- ggplot_obj$data - aes <- ggplot_obj$mapping - geoms <- lapply(ggplot_obj$layers, function(layer) layer$geom) - geom_names = unlist(lapply(geoms, function(geom) class(geom)[[1]])) - - terminal_plot <- plotcli$new( - plot_width, - plot_height, - x_label = ggplot_obj$labels$x, - y_label = ggplot_obj$labels$y, - title = ggplot_obj$labels$title - ) - - for (i in 1:length(geoms)) { - - geom = geoms[[i]] - geom_name <- geom_names[i] - plot_type <- geoms_valid[geoms_valid$geom == geom_name, "plot_type"] - - # Safely extract color aesthetic name (handles factor(col) etc.) - color_aes <- safe_aes_name(aes$colour) - - # FIXME: need to get barplot to work - if (!geom_name %in% geoms_valid$geom | geom_name == "GeomBar") stop("Unsupported geom: ", geom_name) - - if (!is.null(color_aes) && color_aes %in% names(data)) { - - aes_levels <- as.character(unique(data[[color_aes]])) - num_levels <- length(aes_levels) - - this_term_colors <- get_term_colors(num_levels) - - for (j in 1:num_levels) { +#' +#' @examples +#' 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) +ggplotcli <- function(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") { + + # Build the plot to get computed data + built <- ggplot2::ggplot_build(p) + + # Initialize color mapping for all colors in the plot (including legend colors) + # This ensures we minimize color repetition across groups and consistent legend + all_colors <- c() + for (layer_data in built$data) { + if ("colour" %in% names(layer_data)) { + all_colors <- c(all_colors, layer_data$colour) + } + if ("fill" %in% names(layer_data)) { + all_colors <- c(all_colors, layer_data$fill) + } + } - data_subset <- data[data[[color_aes]] == aes_levels[j], ] - data_subset <- get_data_subset(geom_name, data_subset, aes, p_build) + # Also include legend colors for consistent mapping + # Helper to extract colors from a scale (handles both discrete and continuous) + get_scale_colors <- function(scale, n) { + colors <- tryCatch(scale$palette(n), error = function(e) NULL) + if (is.null(colors) || (length(colors) == 1 && is.na(colors[1])) || + all(is.na(colors))) { + colors <- tryCatch(scale$palette(seq(0, 1, length.out = n)), error = function(e) NULL) + } + colors + } - terminal_plot$add_data(list( - x = data_subset$x, - y = data_subset$y, - color = this_term_colors[j], - name = aes_levels[j], - braille = braille, - type = plot_type - )) + # Get legend colors from colour scale + color_scale <- built$plot$scales$get_scales("colour") + if (!is.null(color_scale)) { + tryCatch({ + breaks <- color_scale$get_breaks() + n <- length(breaks) + if (n > 0) { + legend_cols <- get_scale_colors(color_scale, n) + if (!is.null(legend_cols) && !all(is.na(legend_cols))) { + all_colors <- c(all_colors, legend_cols) + } } + }, error = function(e) NULL) + } - } else { - - data_subset <- get_data_subset(geom_name, data, aes, p_build) - this_color = ggplot_obj$layers[[i]]$aes_params$colour - - if(!is.null(this_color)) { - - if(this_color != "") { - - if(!this_color %in% get_term_colors()) this_color = get_term_colors()[i] - + # Get legend colors from fill scale + fill_scale <- built$plot$scales$get_scales("fill") + if (!is.null(fill_scale)) { + tryCatch({ + breaks <- fill_scale$get_breaks() + n <- length(breaks) + if (n > 0) { + legend_cols <- get_scale_colors(fill_scale, n) + if (!is.null(legend_cols) && !all(is.na(legend_cols))) { + all_colors <- c(all_colors, legend_cols) } - } - - terminal_plot$add_data(list( - x = data_subset$x, - y = data_subset$y, - color = this_color, - name = "", - braille = braille, - type = plot_type - )) - } + }, error = function(e) NULL) } - return(terminal_plot) + init_color_mapping(unique(all_colors)) + + # Extract styling from ggplot theme + style <- extract_plot_style(built, border, grid, legend) + + # Get plot labels + labels <- extract_plot_labels(built, title, subtitle, caption, axis_labels) + + # Create style options object + style_opts <- list( + border = style$border, + grid = style$grid, + show_axes = show_axes, + axis_labels = axis_labels, + legend = style$legend, + title_align = title_align, + labels = labels, + boxplot_style = boxplot_style + ) + + # Check for faceting + layout <- built$layout -} \ No newline at end of file +facet_info <- get_facet_info(layout) + + if (facet_info$has_facets) { + # Render faceted plot + render_faceted_plot(built, facet_info, width, height, canvas_type, + style_opts) + } else { + # Render single panel plot + render_single_panel(built, width, height, canvas_type, style_opts) + } +} diff --git a/R/ggplotcli2.r b/R/ggplotcli_helpers.r similarity index 51% rename from R/ggplotcli2.r rename to R/ggplotcli_helpers.r index 8d0439d..38b64dd 100644 --- a/R/ggplotcli2.r +++ b/R/ggplotcli_helpers.r @@ -1,79 +1,6 @@ -#' Convert ggplot2 to Terminal Plot (v2) -#' -#' This is the new implementation using the Canvas abstraction and geom registry. -#' It properly uses ggplot_build() to get computed data and dispatches to -#' registered geom handlers. -#' -#' @param p A ggplot2 object -#' @param width Character width of the plot (default: 60) -#' @param height Character height of the plot (default: 20) -#' @param canvas_type Type of canvas: "braille", "block", or "ascii" (default: "braille") -#' @param border Draw border around plot area. "auto" uses ggplot theme, or TRUE/FALSE (default: "auto") -#' @param grid Grid lines: "none", "major", "minor", "both", or "auto" (default: "none") -#' @param show_axes Whether to show axis values (default: TRUE) -#' @param axis_labels Whether to show axis labels from ggplot (default: TRUE) -#' @param legend Legend display: "auto", "right", "bottom", "none" (default: "auto") -#' @param title_align Title alignment: "center" or "left" (default: "center") -#' @param subtitle Whether to show subtitle (default: TRUE) -#' @param caption Whether to show caption (default: TRUE) -#' @param title Optional title override (NULL uses ggplot title) -#' -#' @return Invisibly returns the canvas object -#' @export -#' -#' @examples -#' library(ggplot2) -#' p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() -#' ggplotcli2(p) -#' ggplotcli2(p, border = TRUE, grid = "major") -ggplotcli2 <- function(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) { - - # Build the plot to get computed data - built <- ggplot2::ggplot_build(p) - - # Extract styling from ggplot theme - style <- extract_plot_style(built, border, grid, legend) - - # Get plot labels - labels <- extract_plot_labels(built, title, subtitle, caption, axis_labels) - - # Create style options object - style_opts <- list( - border = style$border, - grid = style$grid, - show_axes = show_axes, - axis_labels = axis_labels, - legend = style$legend, - title_align = title_align, - labels = labels - ) - - # Check for faceting - layout <- built$layout - facet_info <- get_facet_info(layout) - - if (facet_info$has_facets) { - # Render faceted plot - render_faceted_plot(built, facet_info, width, height, canvas_type, - style_opts) - } else { - # Render single panel plot - render_single_panel(built, width, height, canvas_type, style_opts) - } -} - +#' Null-coalescing operator (if rlang not available) +#' @keywords internal +`%||%` <- function(x, y) if (is.null(x)) y else x #' Extract Plot Style from ggplot Theme #' @keywords internal @@ -148,6 +75,75 @@ extract_plot_labels <- function(built, title, subtitle, caption, axis_labels) { } +#' Extract Legend Information from ggplot +#' @keywords internal +extract_legend_info <- function(built) { + # Try to get color/colour scale + color_scale <- built$plot$scales$get_scales("colour") + fill_scale <- built$plot$scales$get_scales("fill") + + legend_items <- list() + + # Helper to extract colors from a scale (handles both discrete and continuous) + get_scale_colors <- function(scale, n) { + # First try direct palette call (works for discrete scales) + colors <- tryCatch(scale$palette(n), error = function(e) NULL) + + # If that returned NA or NULL, try continuous scale approach + if (is.null(colors) || (length(colors) == 1 && is.na(colors[1])) || + all(is.na(colors))) { + # For continuous scales, palette expects values in [0, 1] + colors <- tryCatch( + scale$palette(seq(0, 1, length.out = n)), + error = function(e) NULL + ) + } + + colors + } + + # Extract from color scale + if (!is.null(color_scale)) { + tryCatch({ + breaks <- color_scale$get_breaks() + labels <- color_scale$get_labels() + n <- length(breaks) + if (n > 0) { + colors <- get_scale_colors(color_scale, n) + if (!is.null(colors) && !all(is.na(colors))) { + legend_items$colour <- list( + title = built$plot$labels$colour %||% "colour", + labels = labels, + colors = colors + ) + } + } + }, error = function(e) NULL) + } + + # Extract from fill scale + if (!is.null(fill_scale)) { + tryCatch({ + breaks <- fill_scale$get_breaks() + labels <- fill_scale$get_labels() + n <- length(breaks) + if (n > 0) { + colors <- get_scale_colors(fill_scale, n) + if (!is.null(colors) && !all(is.na(colors))) { + legend_items$fill <- list( + title = built$plot$labels$fill %||% "fill", + labels = labels, + colors = colors + ) + } + } + }, error = function(e) NULL) + } + + legend_items +} + + #' Render a single panel (non-faceted) plot #' @keywords internal render_single_panel <- function(built, width, height, canvas_type, style_opts) { @@ -180,8 +176,10 @@ render_single_panel <- function(built, width, height, canvas_type, style_opts) { # Create canvas for plot area canvas <- create_canvas(plot_width, plot_height, canvas_type) - # Create scales - scales <- create_scales(built, canvas$pixel_width, canvas$pixel_height) + # Create scales (with border padding if needed, using canvas multipliers) + scales <- create_scales(built, canvas$pixel_width, canvas$pixel_height, + has_border = style_opts$border, + x_mult = canvas$x_mult, y_mult = canvas$y_mult) # Draw grid lines first (behind data) if (style_opts$grid != "none") { @@ -207,9 +205,9 @@ render_single_panel <- function(built, width, height, canvas_type, style_opts) { # Get layer parameters params <- layer$aes_params - # Call handler + # Call handler (pass style_opts for geoms that need it, like boxplot) tryCatch({ - handler(layer_data, canvas, scales, params) + handler(layer_data, canvas, scales, params, style_opts) }, error = function(e) { warning(sprintf("Error rendering %s: %s", geom_class, e$message)) }) @@ -220,6 +218,9 @@ render_single_panel <- function(built, width, height, canvas_type, style_opts) { draw_border(canvas) } + # Extract legend information + legend_info <- extract_legend_info(built) + # Build the final output matrix output <- build_plot_output_v2( canvas = canvas, @@ -228,7 +229,8 @@ render_single_panel <- function(built, width, height, canvas_type, style_opts) { height = height, style_opts = style_opts, left_margin = left_margin, - top_margin = top_margin + top_margin = top_margin, + legend_info = legend_info ) # Print @@ -311,15 +313,17 @@ draw_border <- function(canvas) { #' @param style_opts Style options #' @param left_margin Left margin size #' @param top_margin Top margin size +#' @param legend_info Legend information from extract_legend_info #' @return Character matrix #' @keywords internal build_plot_output_v2 <- function(canvas, scales, width, height, style_opts, - left_margin, top_margin) { + left_margin, top_margin, legend_info = NULL) { # Get rendered canvas rendered <- canvas$render() labels <- style_opts$labels show_axes <- style_opts$show_axes title_align <- style_opts$title_align + legend_position <- style_opts$legend # Create output matrix output <- matrix(" ", nrow = height, ncol = width) @@ -377,43 +381,90 @@ build_plot_output_v2 <- function(canvas, scales, width, height, style_opts, # Draw Y axis values if (show_axes) { - y_ticks <- pretty(scales$y_range, n = 5) - y_ticks <- y_ticks[y_ticks >= scales$y_range[1] & y_ticks <= scales$y_range[2]] - - for (tick in y_ticks) { - y_frac <- (tick - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) - row <- round(nrow(rendered) - y_frac * (nrow(rendered) - 1)) + top_margin - - if (row >= 1 && row <= height) { - label <- format_axis_label(tick) - label_chars <- strsplit(label, "")[[1]] - - start_col <- max(1, left_margin - length(label_chars)) - for (i in seq_along(label_chars)) { - if (start_col + i - 1 < left_margin) { - output[row, start_col + i - 1] <- label_chars[i] + # Check if we have discrete y labels + if (!is.null(scales$y_labels) && length(scales$y_labels) > 0) { + # Use discrete labels for y-axis + for (i in seq_along(scales$y_labels)) { + pos <- scales$y_label_positions[i] + y_frac <- (pos - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) + row <- round(nrow(rendered) - y_frac * (nrow(rendered) - 1)) + top_margin + + if (row >= 1 && row <= height) { + label <- scales$y_labels[i] + label_chars <- strsplit(label, "")[[1]] + + start_col <- max(1, left_margin - length(label_chars)) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 < left_margin) { + output[row, start_col + j - 1] <- label_chars[j] + } + } + } + } + } else { + # Use numeric ticks for y-axis + y_ticks <- pretty(scales$y_range, n = 5) + y_ticks <- y_ticks[y_ticks >= scales$y_range[1] & y_ticks <= scales$y_range[2]] + + for (tick in y_ticks) { + y_frac <- (tick - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) + row <- round(nrow(rendered) - y_frac * (nrow(rendered) - 1)) + top_margin + + if (row >= 1 && row <= height) { + label <- format_axis_label(tick) + label_chars <- strsplit(label, "")[[1]] + + start_col <- max(1, left_margin - length(label_chars)) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 < left_margin) { + output[row, start_col + j - 1] <- label_chars[j] + } } } } } - + # Draw X axis values x_row <- top_margin + nrow(rendered) + 1 - x_ticks <- pretty(scales$x_range, n = 5) - x_ticks <- x_ticks[x_ticks >= scales$x_range[1] & x_ticks <= scales$x_range[2]] - for (tick in x_ticks) { - x_frac <- (tick - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) - col <- round(x_frac * (ncol(rendered) - 1)) + left_margin + 1 + # Check if we have discrete labels + if (!is.null(scales$x_labels) && length(scales$x_labels) > 0) { + # Use discrete labels + for (i in seq_along(scales$x_labels)) { + pos <- scales$x_label_positions[i] + x_frac <- (pos - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) + col <- round(x_frac * (ncol(rendered) - 1)) + left_margin + 1 + + if (col >= left_margin && col <= width && x_row <= height) { + label <- scales$x_labels[i] + label_chars <- strsplit(label, "")[[1]] + + start_col <- col - floor(length(label_chars) / 2) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 >= 1 && start_col + j - 1 <= width) { + output[x_row, start_col + j - 1] <- label_chars[j] + } + } + } + } + } else { + # Use numeric ticks + x_ticks <- pretty(scales$x_range, n = 5) + x_ticks <- x_ticks[x_ticks >= scales$x_range[1] & x_ticks <= scales$x_range[2]] - if (col >= left_margin && col <= width && x_row <= height) { - label <- format_axis_label(tick) - label_chars <- strsplit(label, "")[[1]] + for (tick in x_ticks) { + x_frac <- (tick - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) + col <- round(x_frac * (ncol(rendered) - 1)) + left_margin + 1 - start_col <- col - floor(length(label_chars) / 2) - for (i in seq_along(label_chars)) { - if (start_col + i - 1 >= 1 && start_col + i - 1 <= width) { - output[x_row, start_col + i - 1] <- label_chars[i] + if (col >= left_margin && col <= width && x_row <= height) { + label <- format_axis_label(tick) + label_chars <- strsplit(label, "")[[1]] + + start_col <- col - floor(length(label_chars) / 2) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 >= 1 && start_col + j - 1 <= width) { + output[x_row, start_col + j - 1] <- label_chars[j] + } } } } @@ -462,10 +513,80 @@ build_plot_output_v2 <- function(canvas, scales, width, height, style_opts, } } + # Add legend if present and not "none" + if (!is.null(legend_info) && length(legend_info) > 0 && + !identical(legend_position, "none")) { + output <- add_legend_to_output(output, legend_info, legend_position, + top_margin, nrow(rendered)) + } + return(output) } +#' Add Legend to Output Matrix +#' @keywords internal +add_legend_to_output <- function(output, legend_info, position, top_margin, plot_height) { + # Get the first legend (colour or fill) + legend <- legend_info$colour %||% legend_info$fill + if (is.null(legend)) return(output) + + n_items <- length(legend$labels) + if (n_items == 0) return(output) + + # Calculate legend dimensions - include title width + max_label_len <- max(nchar(legend$labels)) + title_len <- if (!is.null(legend$title)) nchar(legend$title) else 0 + legend_width <- max(max_label_len + 3, title_len + 1) # "* label" or "Title " + + height <- nrow(output) + width <- ncol(output) + + if (position %in% c("right", "auto")) { + # Add legend to the right side + # Create legend column + legend_col <- matrix(" ", nrow = height, ncol = legend_width) + + # Center legend vertically in plot area + legend_start_row <- top_margin + max(1, floor((plot_height - n_items - 1) / 2)) + + # Add title if present + if (!is.null(legend$title) && nchar(legend$title) > 0) { + title_chars <- strsplit(substr(legend$title, 1, legend_width - 1), "")[[1]] + for (i in seq_along(title_chars)) { + if (legend_start_row <= height) { + legend_col[legend_start_row, i] <- title_chars[i] + } + } + legend_start_row <- legend_start_row + 1 + } + + # Add each legend item + for (i in seq_len(n_items)) { + row <- legend_start_row + i - 1 + if (row <= height && row >= 1) { + # Color indicator (use terminal color) + term_color <- color_to_term(legend$colors[i]) + legend_col[row, 1] <- make_colored("*", term_color) + + # Label + label_chars <- strsplit(legend$labels[i], "")[[1]] + for (j in seq_along(label_chars)) { + if (j + 2 <= legend_width) { + legend_col[row, j + 2] <- label_chars[j] + } + } + } + } + + # Append legend to output + output <- cbind(output, legend_col) + } + + output +} + + #' Build Plot Output with Axes and Title (legacy) #' #' @param canvas The rendered canvas @@ -481,13 +602,14 @@ build_plot_output <- function(canvas, scales, width, height, show_axes, title) { style_opts <- list( show_axes = show_axes, title_align = "center", + legend = "none", labels = list(title = title, subtitle = NULL, caption = NULL, x = NULL, y = NULL) ) left_margin <- if (show_axes) 6 else 0 top_margin <- if (!is.null(title)) 1 else 0 - build_plot_output_v2(canvas, scales, width, height, style_opts, left_margin, top_margin) + build_plot_output_v2(canvas, scales, width, height, style_opts, left_margin, top_margin, NULL) } @@ -497,6 +619,11 @@ build_plot_output <- function(canvas, scales, width, height, show_axes, title) { #' @return Formatted string #' @keywords internal format_axis_label <- function(value) { + # Handle exact zero + if (value == 0) { + return("0") + } + # Use scientific notation for very small or very large numbers if (abs(value) < 0.01 || abs(value) >= 10000) { sprintf("%.1e", value) } else if (abs(value) < 1) { @@ -584,18 +711,24 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, show_axes <- style_opts$show_axes # Calculate dimensions for each panel - # Reserve space for: title, facet labels, axes - top_margin <- if (!is.null(labels$title)) 2 else 1 + # Reserve space for: title, subtitle, facet labels, axes, x label + top_margin <- 1 # At least 1 for facet labels + if (!is.null(labels$title)) top_margin <- top_margin + 1 + if (!is.null(labels$subtitle)) top_margin <- top_margin + 1 + bottom_margin <- 2 # For x-axis values + if (!is.null(labels$x)) bottom_margin <- bottom_margin + 1 # Extra row for x label left_margin <- if (show_axes) 7 else 0 + if (!is.null(labels$y) && left_margin > 0) left_margin <- left_margin + 1 # Extra col for y label # Calculate panel dimensions panel_width <- floor((width - left_margin) / n_cols) - panel_height <- floor((height - top_margin - 2) / n_rows) # -2 for x-axis + panel_height <- floor((height - top_margin - bottom_margin) / n_rows) # Create output matrix output <- matrix(" ", nrow = height, ncol = width) # Add title if present + current_row <- 1 if (!is.null(labels$title)) { title_chars <- strsplit(substr(labels$title, 1, width), "")[[1]] if (style_opts$title_align == "center") { @@ -604,7 +737,21 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, start_col <- left_margin + 1 } for (i in seq_along(title_chars)) { - output[1, start_col + i - 1] <- title_chars[i] + output[current_row, start_col + i - 1] <- title_chars[i] + } + current_row <- current_row + 1 + } + + # Add subtitle if present + if (!is.null(labels$subtitle)) { + sub_chars <- strsplit(substr(labels$subtitle, 1, width), "")[[1]] + if (style_opts$title_align == "center") { + start_col <- max(1, floor((width - length(sub_chars)) / 2)) + } else { + start_col <- left_margin + 1 + } + for (i in seq_along(sub_chars)) { + output[current_row, start_col + i - 1] <- sub_chars[i] } } @@ -629,9 +776,11 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, canvas <- create_canvas(canvas_width, canvas_height, canvas_type) - # Create scales for this panel + # Create scales for this panel (with border padding if needed, using canvas multipliers) panel_params <- built$layout$panel_params[[panel_idx]] - scales <- create_panel_scales(panel_params, canvas$pixel_width, canvas$pixel_height) + scales <- create_panel_scales(panel_params, canvas$pixel_width, canvas$pixel_height, + has_border = style_opts$border, + x_mult = canvas$x_mult, y_mult = canvas$y_mult) # Draw grid lines first (behind data) if (style_opts$grid != "none") { @@ -658,9 +807,9 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, if (is.null(handler)) next - # Render + # Render (pass style_opts for geoms that need it, like boxplot) tryCatch({ - handler(panel_data, canvas, scales, layer$aes_params) + handler(panel_data, canvas, scales, layer$aes_params, style_opts) }, error = function(e) { warning(sprintf("Error rendering %s in panel %d: %s", geom_class, panel_idx, e$message)) @@ -699,20 +848,42 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, # Add Y axis for leftmost panels if (panel_col == 1 && show_axes) { - y_ticks <- pretty(scales$y_range, n = 3) - y_ticks <- y_ticks[y_ticks >= scales$y_range[1] & y_ticks <= scales$y_range[2]] - - for (tick in y_ticks) { - y_frac <- (tick - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) - row <- out_row_start + 1 + round((1 - y_frac) * (canvas_height - 1)) - - if (row >= 1 && row <= height) { - label <- format_axis_label(tick) - label_chars <- strsplit(label, "")[[1]] - start_col <- max(1, left_margin - length(label_chars)) - for (i in seq_along(label_chars)) { - if (start_col + i - 1 <= left_margin && start_col + i - 1 >= 1) { - output[row, start_col + i - 1] <- label_chars[i] + # Check if we have discrete y labels + if (!is.null(scales$y_labels) && length(scales$y_labels) > 0) { + # Use discrete labels for y-axis + for (i in seq_along(scales$y_labels)) { + pos <- scales$y_label_positions[i] + y_frac <- (pos - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) + row <- out_row_start + 1 + round((1 - y_frac) * (canvas_height - 1)) + + if (row >= 1 && row <= height) { + label <- scales$y_labels[i] + label_chars <- strsplit(label, "")[[1]] + start_col <- max(1, left_margin - length(label_chars)) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 <= left_margin && start_col + j - 1 >= 1) { + output[row, start_col + j - 1] <- label_chars[j] + } + } + } + } + } else { + # Use numeric ticks for y-axis + y_ticks <- pretty(scales$y_range, n = 3) + y_ticks <- y_ticks[y_ticks >= scales$y_range[1] & y_ticks <= scales$y_range[2]] + + for (tick in y_ticks) { + y_frac <- (tick - scales$y_range[1]) / (scales$y_range[2] - scales$y_range[1]) + row <- out_row_start + 1 + round((1 - y_frac) * (canvas_height - 1)) + + if (row >= 1 && row <= height) { + label <- format_axis_label(tick) + label_chars <- strsplit(label, "")[[1]] + start_col <- max(1, left_margin - length(label_chars)) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 <= left_margin && start_col + j - 1 >= 1) { + output[row, start_col + j - 1] <- label_chars[j] + } } } } @@ -723,20 +894,42 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, if (panel_row == n_rows && show_axes) { x_row <- out_row_start + canvas_height + 1 if (x_row <= height) { - x_ticks <- pretty(scales$x_range, n = 3) - x_ticks <- x_ticks[x_ticks >= scales$x_range[1] & x_ticks <= scales$x_range[2]] - - for (tick in x_ticks) { - x_frac <- (tick - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) - col <- out_col_start + round(x_frac * (canvas_width - 1)) + # Check if we have discrete labels + if (!is.null(scales$x_labels) && length(scales$x_labels) > 0) { + # Use discrete labels + for (i in seq_along(scales$x_labels)) { + pos <- scales$x_label_positions[i] + x_frac <- (pos - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) + col <- out_col_start + round(x_frac * (canvas_width - 1)) + + if (col >= 1 && col <= width) { + label <- scales$x_labels[i] + label_chars <- strsplit(label, "")[[1]] + start_col <- col - floor(length(label_chars) / 2) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 >= 1 && start_col + j - 1 <= width) { + output[x_row, start_col + j - 1] <- label_chars[j] + } + } + } + } + } else { + # Use numeric ticks + x_ticks <- pretty(scales$x_range, n = 3) + x_ticks <- x_ticks[x_ticks >= scales$x_range[1] & x_ticks <= scales$x_range[2]] - if (col >= 1 && col <= width) { - label <- format_axis_label(tick) - label_chars <- strsplit(label, "")[[1]] - start_col <- col - floor(length(label_chars) / 2) - for (i in seq_along(label_chars)) { - if (start_col + i - 1 >= 1 && start_col + i - 1 <= width) { - output[x_row, start_col + i - 1] <- label_chars[i] + for (tick in x_ticks) { + x_frac <- (tick - scales$x_range[1]) / (scales$x_range[2] - scales$x_range[1]) + col <- out_col_start + round(x_frac * (canvas_width - 1)) + + if (col >= 1 && col <= width) { + label <- format_axis_label(tick) + label_chars <- strsplit(label, "")[[1]] + start_col <- col - floor(length(label_chars) / 2) + for (j in seq_along(label_chars)) { + if (start_col + j - 1 >= 1 && start_col + j - 1 <= width) { + output[x_row, start_col + j - 1] <- label_chars[j] + } } } } @@ -745,6 +938,46 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, } } + # Add Y axis label (vertically on the left) + if (!is.null(labels$y) && left_margin >= 2) { + y_label <- labels$y + y_chars <- strsplit(substr(y_label, 1, min(nchar(y_label), panel_height * n_rows)), "")[[1]] + label_start <- top_margin + floor((panel_height * n_rows - length(y_chars)) / 2) + for (i in seq_along(y_chars)) { + row <- label_start + i + if (row >= 1 && row <= height) { + output[row, 1] <- y_chars[i] + } + } + } + + # Add X axis label (centered at bottom) + if (!is.null(labels$x)) { + x_row <- top_margin + panel_height * n_rows + 2 + if (x_row <= height) { + x_label <- substr(labels$x, 1, width - left_margin) + x_chars <- strsplit(x_label, "")[[1]] + # Center across all panels + plot_area_width <- panel_width * n_cols + start_col <- left_margin + floor((plot_area_width - length(x_chars)) / 2) + for (i in seq_along(x_chars)) { + if (start_col + i - 1 >= 1 && start_col + i - 1 <= width) { + output[x_row, start_col + i - 1] <- x_chars[i] + } + } + } + } + + # Add legend if present + legend_info <- extract_legend_info(built) + if (!is.null(legend_info) && length(legend_info) > 0 && + !identical(style_opts$legend, "none")) { + # Calculate plot height for legend centering + plot_height <- panel_height * n_rows + output <- add_legend_to_output(output, legend_info, style_opts$legend, + top_margin, plot_height) + } + # Print cat("\n") for (i in seq_len(nrow(output))) { @@ -760,24 +993,94 @@ render_faceted_plot <- function(built, facet_info, width, height, canvas_type, #' @param panel_params Panel parameters from ggplot_build #' @param plot_width Pixel width #' @param plot_height Pixel height +#' @param has_border Whether a border will be drawn (adds padding) #' @return List with scale functions #' @keywords internal -create_panel_scales <- function(panel_params, plot_width, plot_height) { +create_panel_scales <- function(panel_params, plot_width, plot_height, has_border = FALSE, + x_mult = 1, y_mult = 1) { + # Get x and y ranges from panel params x_range <- panel_params$x.range y_range <- panel_params$y.range - + # Fallback if ranges not available if (is.null(x_range)) x_range <- c(0, 1) if (is.null(y_range)) y_range <- c(0, 1) + + # Add padding if border is present to prevent data from overlapping border + # Padding must be at least the canvas multiplier to ensure data stays in + # a different character cell than the border (e.g., braille is 2x4 per char) + if (has_border) { + x_padding <- x_mult + 1 # Move past border character cell + y_padding <- y_mult + 1 + } else { + x_padding <- 0 + y_padding <- 0 + } + x_min <- 1 + x_padding + x_max <- plot_width - x_padding + y_min <- 1 + y_padding + y_max <- plot_height - y_padding + + # Ensure we have valid ranges + if (x_max <= x_min) { + x_min <- 1 + x_max <- plot_width + } + if (y_max <= y_min) { + y_min <- 1 + y_max <- plot_height + } # Create scaling functions x_scale <- function(x) { - ((x - x_range[1]) / (x_range[2] - x_range[1])) * (plot_width - 1) + 1 + ((x - x_range[1]) / (x_range[2] - x_range[1])) * (x_max - x_min) + x_min } y_scale <- function(y) { - plot_height - ((y - y_range[1]) / (y_range[2] - y_range[1])) * (plot_height - 1) + y_max - ((y - y_range[1]) / (y_range[2] - y_range[1])) * (y_max - y_min) + } + + # Check for discrete x-axis labels (only use labels for discrete scales) + x_labels <- NULL + x_label_positions <- NULL + x_is_discrete <- !is.null(panel_params$x) && + !is.null(panel_params$x$is_discrete) && + tryCatch(panel_params$x$is_discrete(), error = function(e) FALSE) + + if (x_is_discrete && !is.null(panel_params$x$breaks)) { + x_labels <- panel_params$x$get_labels() + x_label_positions <- attr(panel_params$x$breaks, "pos") + if (is.null(x_label_positions)) { + x_label_positions <- seq_along(x_labels) + } + # Filter out NA values from labels and positions + if (!is.null(x_labels) && length(x_labels) > 0) { + valid <- !is.na(x_labels) + x_labels <- x_labels[valid] + x_label_positions <- x_label_positions[valid] + } + } + + # Check for discrete y-axis labels (only use labels for discrete scales) + y_labels <- NULL + y_label_positions <- NULL + y_is_discrete <- !is.null(panel_params$y) && + !is.null(panel_params$y$is_discrete) && + tryCatch(panel_params$y$is_discrete(), error = function(e) FALSE) + + if (y_is_discrete && !is.null(panel_params$y$breaks)) { + y_labels <- panel_params$y$get_labels() + y_label_positions <- attr(panel_params$y$breaks, "pos") + if (is.null(y_label_positions)) { + y_label_positions <- seq_along(y_labels) + } + # Filter out NA values from labels and positions + if (!is.null(y_labels) && length(y_labels) > 0) { + valid <- !is.na(y_labels) + y_labels <- y_labels[valid] + y_label_positions <- y_label_positions[valid] + } } list( @@ -786,7 +1089,11 @@ create_panel_scales <- function(panel_params, plot_width, plot_height) { x_range = x_range, y_range = y_range, width = plot_width, - height = plot_height + height = plot_height, + x_labels = x_labels, + x_label_positions = x_label_positions, + y_labels = y_labels, + y_label_positions = y_label_positions ) } diff --git a/R/helper_functions.r b/R/helper_functions.r index 0f70871..1bdebc3 100644 --- a/R/helper_functions.r +++ b/R/helper_functions.r @@ -1,3 +1,6 @@ +#' @importFrom crayon blue red green yellow magenta cyan silver white black +NULL + #' Print plot matrix #' #' This function prints a plot matrix to the console. @@ -131,6 +134,9 @@ normalize_data <- function(data, data_min, data_max, plot_range) { + if (data_max == data_min) { + return(rep(round(plot_range / 2), length(data))) + } val <- ((data - data_min) / (data_max - data_min) * (plot_range)) + 1 val[val < 1] <- 1 val[val > plot_range] <- plot_range @@ -204,25 +210,27 @@ remove_color_codes <- function(s) { #' @examples #' is_braille("A") is_braille <- function(char) { + if (is.null(char) || length(char) == 0 || nchar(char) == 0) return(FALSE) + # Get the first character's code (ignore ANSI escape sequences) code <- utf8ToInt(char) - return((code >= 0x2800 && code <= 0x28FF)) + if (length(code) == 0) return(FALSE) + # Check only the first code point + code <- code[1] + return(code >= 0x2800 && code <= 0x28FF) } #' Get Braille dot bit value #' #' Returns the bit value for a specific dot position in a Braille cell. -#' Braille cells have a 2x4 dot matrix: +#' Braille cells have a 2x4 dot matrix with the following bit values: #' -#' Col 0 Col 1 -#' ┌────┬────┐ -#' Row 0 │ 0x01│ 0x08│ -#' ├────┼────┤ -#' Row 1 │ 0x02│ 0x10│ -#' ├────┼────┤ -#' Row 2 │ 0x04│ 0x20│ -#' ├────┼────┤ -#' Row 3 │ 0x40│ 0x80│ -#' └────┴────┘ +#' \preformatted{ +#' Col 0 Col 1 +#' Row 0: 0x01 0x08 +#' Row 1: 0x02 0x10 +#' Row 2: 0x04 0x20 +#' Row 3: 0x40 0x80 +#' } #' #' @param dot_row Row within the Braille cell (0-3, top to bottom) #' @param dot_col Column within the Braille cell (0-1, left to right) diff --git a/R/plotcli.r b/R/plotcli.r index b92522c..ab864d0 100644 --- a/R/plotcli.r +++ b/R/plotcli.r @@ -465,9 +465,15 @@ plotcli <- R6Class("plotcli", if (is.null(self$xlim)) { x_range <- self$x_max - self$x_min - cushion_x <- x_range * cushion_percentage - self$x_min <- self$x_min - cushion_x - self$x_max <- self$x_max + cushion_x + if (x_range == 0) { + expand <- if (self$x_min == 0) 1 else abs(self$x_min) * 0.05 + self$x_min <- self$x_min - expand + self$x_max <- self$x_max + expand + } else { + cushion_x <- x_range * cushion_percentage + self$x_min <- self$x_min - cushion_x + self$x_max <- self$x_max + cushion_x + } } else { self$x_min <- self$xlim[1] self$x_max <- self$xlim[2] @@ -475,9 +481,15 @@ plotcli <- R6Class("plotcli", if (is.null(self$ylim)) { y_range <- self$y_max - self$y_min - cushion_y <- y_range * cushion_percentage - self$y_min <- self$y_min - cushion_y - self$y_max <- self$y_max + cushion_y + if (y_range == 0) { + expand <- if (self$y_min == 0) 1 else abs(self$y_min) * 0.05 + self$y_min <- self$y_min - expand + self$y_max <- self$y_max + expand + } else { + cushion_y <- y_range * cushion_percentage + self$y_min <- self$y_min - cushion_y + self$y_max <- self$y_max + cushion_y + } } else { self$y_min <- self$ylim[1] self$y_max <- self$ylim[2] diff --git a/R/zzz.r b/R/zzz.r index 0707c3b..688cab0 100644 --- a/R/zzz.r +++ b/R/zzz.r @@ -1,3 +1,11 @@ +.onLoad <- function(libname, pkgname) { + # Enable crayon colors even in non-interactive sessions (e.g., Rscript) + # This ensures colored output works when running scripts + if (is.null(getOption("crayon.enabled"))) { + options(crayon.enabled = TRUE) + } +} + .onAttach <- function(libname, pkgname) { # Set default options plotcli_options(plot_width = 60, plot_height = 20, braille = FALSE) diff --git a/README.md b/README.md index 6dbe499..9a86f98 100644 --- a/README.md +++ b/README.md @@ -1,111 +1,192 @@ -# plotcli: Command-Line Plots for R +# plotcli: ggplot2 in Your Terminal [](https://CRAN.R-project.org/package=plotcli) [](https://cran.r-project.org/web/checks/check_results_plotcli.html) -[](http://www.r-pkg.org/pkg/plotcli) -[](http://www.r-pkg.org/pkg/plotcli) +[](https://www.r-pkg.org/pkg/plotcli) +[](https://www.r-pkg.org/pkg/plotcli) +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
ggplotcli is a universal converter that renders any
+ggplot2 plot in the terminal using Unicode/ASCII characters. It
+automatically extracts data, aesthetics, and styling from ggplot
+objects, supporting 15+ geom types, faceting, color aesthetics, and
+legends.
library(plotcli)
+#> Loading required package: R6
+#> Loading required package: ggplot2
+#> plotcli loaded. Use plotcli_options() to set global options.
+library(ggplot2)
+
+# Create a ggplot
+p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
+ geom_point() +
+ labs(title = "MPG vs Weight by Cylinders")
+
+# Render in terminal
+ggplotcli(p, width = 60, height = 16)
+#>
+#> MPG vs Weight by Cylinders
+#> 35.0 [31m⠄[39m
+#> [31m⠐[39m
+#> 30.0 [31m⠐[39m[31m⠐[39m
+#> [31m⠠[39m factor(cyl)
+#> m 25.0 [31m⠁[39m [31m⢀[39m [31m*[39m 4
+#> p [31m⠄[39m [31m⠄[39m [36m*[39m 6
+#> g 20.0 [31m⠐[39m [36m⠠[39m [31m⠐[39m[36m⠠[39m [36m⠐[39m [35m*[39m 8
+#> [36m⠈[39m [36m⢰[39m [35m⠐[39m
+#> [35m⡀[39m [35m⠁[39m [35m⠄[39m
+#> 15.0 [35m⠈[39m[35m⠈[39m[35m⠆[39m [35m⠈[39m [35m⠂[39m
+#> [35m⠁[39m
+#> 10.0 [35m⠂[39m [35m⠂[39m
+#> 2.0 3.0 4.0 5.0
+#> wt
+#> p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
+ geom_point() +
+ labs(title = "Iris: Sepal Dimensions by Species")
+ggplotcli(p, width = 60, height = 16)
+#>
+#> Iris: Sepal Dimensions by Species
+#> S 4.5 [31m⠠[39m
+#> e [31m⡀[39m [31m⠄[39m
+#> p 4.0 [31m⢀[39m [31m⠂[39m
+#> a [31m⢐[39m [31m⢀[39m[31m⢀[39m [31m⠐[39m [35m⠐[39m [35m⠂[39m Species
+#> l 3.5 [31m⠁[39m [31m⠁[39m[31m⠨[39m[31m⠠[39m [31m⠄[39m [31m⠄[39m [35m⠁[39m [31m*[39m setosa
+#> . [31m⢀[39m [31m⡁[39m[31m⢀[39m [31m⠁[39m [31m⢨[39m[31m⠨[39m [31m⠁[39m [31m⠈[39m [36m⡀[39m[36m⠈[39m [35m⠁[39m[35m⠨[39m[35m⢀[39m [35m⡀[39m [35m⠠[39m [35m⡀[39m[35m⡀[39m[36m⢀[39m [35m⡀[39m [36m*[39m versicolor
+#> W 3.0 [31m⢀[39m[31m⢀[39m [31m⠂[39m [31m⡂[39m[31m⡂[39m[31m⢀[39m [36m⢀[39m [36m⡀[39m[36m⢀[39m [35m⡀[39m[35m⢀[39m[35m⢀[39m [35m⠐[39m [35m⡀[39m[36m⢀[39m[35m⢐[39m [35m⡀[39m[35m⠂[39m [35m⡀[39m[35m⡀[39m [35m⢀[39m[35m⢀[39m [35m*[39m virginica
+#> i [31m⠐[39m [35m⡂[39m[36m⢐[39m [35m⡀[39m [36m⠐[39m[36m⢐[39m [35m⡂[39m[35m⢐[39m[35m⢐[39m [36m⡀[39m[36m⠐[39m [36m⡀[39m [35m⠐[39m[35m⢀[39m [35m⢀[39m
+#> d 2.5 [36m⠁[39m [36m⠄[39m[36m⠁[39m[36m⠠[39m [35m⠅[39m [36m⠈[39m[35m⠠[39m [35m⠈[39m[35m⠈[39m [35m⠠[39m
+#> t [35m⠅[39m [36m⠈[39m [36m⠅[39m[36m⠁[39m[35m⠈[39m [35m⠈[39m [35m⠈[39m
+#> h [31m⠁[39m [36m⠈[39m [36m⠁[39m [35m⠐[39m [36m⠂[39m[36m⠈[39m
+#> 2.0 [36m⠐[39m
+#> 5.0 6.0 7.0 8.0
+#> Sepal.Length
+#> # Multiple colored lines
+df <- data.frame(
+ x = rep(1:30, 2),
+ y = c(sin(1:30/4) * 10, cos(1:30/4) * 10),
+ type = rep(c("sin", "cos"), each = 30)
+)
+p <- ggplot(df, aes(x, y, color = type)) +
+ geom_line() +
+ labs(title = "Sine and Cosine Waves")
+ggplotcli(p, width = 60, height = 12)
+#>
+#> Sine and Cosine Waves
+#> 10.0 [31m⠠[39m[31m⢄[39m[31m⡀[39m [35m⣀[39m[35m⠤[39m[35m⠒[39m[35m⠢[39m[35m⠤[39m[35m⣀[39m[35m⡀[39m [31m⣀[39m[31m⠤[39m[31m⠔[39m[31m⠒[39m[31m⠤[39m[31m⠤[39m[31m⣀[39m [35m⣀[39m[35m⠄[39m
+#> [31m⠈[39m[35m⡱[39m[35m⢖[39m[35m⠉[39m [35m⠈[39m[35m⠑[39m[35m⠤[39m[35m⡀[39m [31m⣀[39m[31m⠔[39m[31m⠊[39m [35m⢉[39m[35m⠶[39m[35m⢎[39m type
+#> 5.0 [35m⡠[39m[35m⠊[39m [31m⠑[39m[31m⠢[39m[31m⡀[39m [35m⠈[39m[35m⠢[39m[35m⡀[39m [31m⢠[39m[31m⠊[39m [35m⣀[39m[35m⠔[39m[35m⠁[39m [31m⠣[39m[31m⡀[39m [31m*[39m cos
+#> y [35m⠈[39m [31m⠘[39m[31m⢄[39m [35m⠑[39m[35m⢄[39m [31m⢀[39m[31m⠔[39m[31m⠁[39m [35m⢠[39m[35m⠊[39m [35m*[39m sin
+#> 0 [31m⠑[39m[31m⢄[39m [35m⠑[39m[35m⠤[39m[35m⡀[39m [31m⢀[39m[31m⠔[39m[31m⠁[39m [35m⢀[39m[35m⠔[39m[35m⠁[39m
+#> -5.0 [31m⠑[39m[31m⠤[39m[31m⡀[39m [35m⠈[39m[35m⢆[39m [31m⢀[39m[31m⠔[39m[31m⠁[39m [35m⡰[39m[35m⠁[39m
+#> [31m⠈[39m[31m⠢[39m[31m⡀[39m [35m⡱[39m[35m⠶[39m[35m⣁[39m [35m⡠[39m[35m⠒[39m[35m⠉[39m
+#> -10.0 [31m⠈[39m[31m⠑[39m[31m⠒[39m[31m⠒[39m[31m⠤[39m[31m⠤[39m[31m⠒[39m[31m⠉[39m [35m⠉[39m[35m⠑[39m[35m⠒[39m[35m⠤[39m[35m⠔[39m[35m⠒[39m[35m⠉[39m
+#> 0 5.0 10.0 15.0 20.0 25.0 30.0
+#> x
+#> p <- ggplot(mtcars, aes(x = mpg, fill = factor(cyl))) +
+ geom_histogram(bins = 10, position = "dodge") +
+ labs(title = "MPG Distribution by Cylinders")
+ggplotcli(p, width = 60, height = 12)
+#>
+#> MPG Distribution by Cylinders
+#> [35m⣶[39m[35m⣶[39m
+#> c 6.0 [35m⣿[39m[35m⣿[39m factor(cyl)
+#> o [35m⣿[39m[35m⣿[39m [31m*[39m 4
+#> u 4.0 [35m⣿[39m[35m⣿[39m [36m⢰[39m[36m⣶[39m[36m⡆[39m [36m*[39m 6
+#> n [35m⣿[39m[35m⣿[39m [36m⣤[39m[35m⣤[39m[35m⣤[39m[35m⡄[39m[36m⢸[39m[36m⣿[39m[36m⡇[39m[31m⢠[39m[31m⣤[39m[31m⣤[39m [31m⣤[39m[31m⣤[39m [35m*[39m 8
+#> t 2.0 [35m⢠[39m[35m⣤[39m[35m⡄[39m [35m⣤[39m[35m⣤[39m [35m⣿[39m[35m⣿[39m [36m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣧[39m[36m⣼[39m[36m⣿[39m[36m⡇[39m[31m⢸[39m[31m⣿[39m[31m⣿[39m [31m⢠[39m[31m⣤[39m[31m⡄[39m [31m⣿[39m[31m⣿[39m
+#> [35m⢸[39m[35m⣿[39m[35m⡇[39m [35m⣿[39m[35m⣿[39m [35m⣿[39m[35m⣿[39m [36m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[36m⣿[39m[36m⣿[39m[36m⡇[39m[31m⢸[39m[31m⣿[39m[31m⣿[39m [31m⢸[39m[31m⣿[39m[31m⡇[39m [31m⣿[39m[31m⣿[39m [31m⢠[39m[31m⣤[39m[31m⡄[39m
+#> 0 [31m⠠[39m[31m⠤[39m[36m⠤[39m[35m⠼[39m[35m⠿[39m[35m⠧[39m[36m⠤[39m[36m⠤[39m[35m⠿[39m[35m⠿[39m[31m⠤[39m[36m⠤[39m[36m⠤[39m[35m⠿[39m[35m⠿[39m[31m⠤[39m[36m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[36m⠿[39m[36m⠿[39m[35m⠧[39m[35m⠼[39m[31m⠿[39m[36m⠿[39m[36m⠤[39m[35m⠤[39m[35m⠼[39m[31m⠿[39m[36m⠧[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[36m⠤[39m[36m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠿[39m[36m⠿[39m[36m⠤[39m[35m⠤[39m[35m⠼[39m[31m⠿[39m[36m⠧[39m[35m⠤[39m[35m⠤[39m[35m⠄[39m
+#> 10.0 15.0 20.0 25.0 30.0 35.0
+#> mpg
+#> p <- ggplot(mtcars, aes(x = mpg, color = factor(cyl))) +
+ geom_density() +
+ labs(title = "MPG Density by Cylinders")
+ggplotcli(p, width = 60, height = 12)
+#>
+#> MPG Density by Cylinders
+#> d 0.25 [35m⣠[39m[35m⢦[39m
+#> e 0.20 [35m⢠[39m[35m⠃[39m[35m⠈[39m[35m⣇[39m [36m⢀[39m[36m⡠[39m[36m⠞[39m[36m⠙[39m[36m⣆[39m factor(cyl)
+#> n [35m⡞[39m [35m⠸[39m[35m⡀[39m [36m⢠[39m[36m⠚[39m[36m⠉[39m[36m⠁[39m [36m⠸[39m[36m⡄[39m [31m*[39m 4
+#> s 0.15 [35m⢠[39m[35m⠃[39m [35m⢣[39m [36m⢠[39m[36m⠃[39m [36m⢧[39m [36m*[39m 6
+#> i 0.10 [35m⢀[39m[35m⡎[39m [35m⠈[39m[35m⢆[39m[36m⡎[39m [36m⠘[39m[36m⡄[39m [35m*[39m 8
+#> t 0.05 [35m⠘[39m[35m⢦[39m [35m⢀[39m[35m⡞[39m [35m⡼[39m[35m⠳[39m[35m⠤[39m[35m⠖[39m[35m⠒[39m[35m⢦[39m [31m⢀[39m[31m⣠[39m[31m⠤[39m[31m⠖[39m[36m⢳[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠦[39m[31m⠤[39m[31m⠤[39m[31m⣄[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m
+#> y [35m⠈[39m[35m⢣[39m[35m⡀[39m[35m⣠[39m[35m⠞[39m [36m⡰[39m[36m⠁[39m [31m⢀[39m[31m⣀[39m[31m⡤[39m[31m⠔[39m[35m⢻[39m[35m⡉[39m [36m⠈[39m[36m⢧[39m [31m⠈[39m[31m⠉[39m[31m⠉[39m[31m⠓[39m[31m⠂[39m
+#> 0 [36m⠠[39m[36m⠤[39m[36m⠤[39m[35m⠭[39m[35m⠥[39m[36m⠤[39m[36m⠤[39m[36m⠤[39m[36m⠴[39m[36m⠶[39m[36m⠒[39m[36m⠚[39m[36m⠓[39m[31m⠒[39m[31m⠉[39m[31m⠉[39m [35m⠙[39m[35m⠒[39m[35m⠦[39m[35m⠤[39m[35m⠤[39m[35m⠬[39m[35m⠷[39m[35m⠶[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠄[39m
+#> 10.0 15.0 20.0 25.0 30.0 35.0
+#> mpg
+#> df <- data.frame(
+ category = c("A", "B", "C", "D", "E", "F"),
+ value = c(25, 45, 30, 60, 35, 50)
+)
+p <- ggplot(df, aes(x = category, y = value, fill = category)) +
+ geom_col() +
+ labs(title = "Category Values")
+ggplotcli(p, width = 60, height = 12)
+#>
+#> Category Values
+#> 60.0 [36m⣶[39m[36m⣶[39m[36m⣶[39m[36m⣶[39m[36m⣶[39m[36m⣶[39m[36m⣶[39m[36m⣶[39m category
+#> v 50.0 [36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m [35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m [31m*[39m A
+#> a 40.0 [33m⢸[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⡇[39m [36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m [35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m [33m*[39m B
+#> l 30.0 [33m⢸[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⡇[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[32m⣀[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[34m⢰[39m[34m⣶[39m[34m⣶[39m[34m⣶[39m[34m⣶[39m[34m⣶[39m[34m⣶[39m[34m⣶[39m[34m⡆[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m [32m*[39m C
+#> u [31m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣤[39m[33m⢸[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⡇[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[34m⢸[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⡇[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m [36m*[39m D
+#> e 20.0 [31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[33m⢸[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⡇[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[34m⢸[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⡇[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m [34m*[39m E
+#> 10.0 [31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[33m⢸[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⣿[39m[33m⡇[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[32m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[36m⣿[39m[34m⢸[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⣿[39m[34m⡇[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m [35m*[39m F
+#> 0 [31m⠿[39m[31m⠿[39m[31m⠿[39m[31m⠿[39m[31m⠿[39m[31m⠿[39m[31m⠿[39m[31m⠿[39m[33m⠸[39m[33m⠿[39m[33m⠿[39m[33m⠿[39m[33m⠿[39m[33m⠿[39m[33m⠿[39m[33m⠿[39m[33m⠇[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[32m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[36m⠿[39m[34m⠸[39m[34m⠿[39m[34m⠿[39m[34m⠿[39m[34m⠿[39m[34m⠿[39m[34m⠿[39m[34m⠿[39m[34m⠇[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m
+#> A B C D E F
+#> category
+#> Boxplots are rendered with box-drawing characters by default, showing +whiskers, box (Q1-Q3), median line, and outliers:
+set.seed(42)
+df <- data.frame(
+ group = factor(rep(paste0("Group ", 1:6), each = 50)),
+ value = c(rnorm(50, 10, 3), rnorm(50, 5, 2), rnorm(50, 8, 4),
+ rnorm(50, 6, 2), rnorm(50, 12, 3), rnorm(50, 7, 2))
+)
+p <- ggplot(df, aes(x = group, y = value, fill = group)) +
+ geom_boxplot() +
+ labs(title = "Boxplot Colored by Group", y = "Value", x = "Group")
+ggplotcli(p, width = 80, height = 20, boxplot_style = "ascii")
+#>
+#> Boxplot Colored by Group
+#> [32m*[39m [34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m
+#> [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [34m│[39m
+#> [31m│[39m [32m*[39m [34m│[39m
+#> 15.0 [31m│[39m [34m┌[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m┐[39m group
+#> [31m│[39m [32m─[39m[32m─[39m[32m─[39m[32m*[39m[32m─[39m[32m─[39m[32m─[39m [34m│[39m [34m│[39m [31m*[39m Group 1
+#> V [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m [32m│[39m [34m│[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m│[39m [35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m [33m*[39m Group 2
+#> a [31m│[39m [31m│[39m [32m│[39m [34m└[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m┘[39m [35m│[39m [32m*[39m Group 3
+#> l 10.0 [31m│[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m│[39m [32m┌[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┐[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [34m│[39m [35m│[39m [36m*[39m Group 4
+#> u [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m [32m│[39m [32m│[39m [36m┌[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┐[39m [34m│[39m [35m┌[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m┐[39m [34m*[39m Group 5
+#> e [31m│[39m [33m┌[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┐[39m [32m└[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┘[39m [36m│[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m│[39m [34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m [35m│[39m [35m│[39m [35m*[39m Group 6
+#> 5.0 [31m│[39m [33m│[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m│[39m [32m│[39m [36m└[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┘[39m [35m└[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m┘[39m
+#> [31m│[39m [33m└[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┘[39m [32m│[39m [36m│[39m [35m│[39m
+#> [31m─[39m[31m─[39m[31m─[39m[31m*[39m[31m─[39m[31m─[39m[31m─[39m [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m [32m│[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m
+#> [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m
+#> 0 [33m*[39m [32m*[39m
+#>
+#> Group 1 Group 2 Group 3 Group 4 Group 5 Group 6
+#> Group
+#> You can also use Braille rendering for boxplots:
+ggplotcli(p, width = 80, height = 20, boxplot_style = "braille")
+#>
+#> Boxplot Colored by Group
+#> [32m⡀[39m
+#> [34m⠒[39m[34m⠒[39m[34m⡖[39m[34m⠒[39m[34m⠂[39m
+#> [31m⠉[39m[31m⠉[39m[31m⡏[39m[31m⠉[39m[31m⠁[39m [34m⡇[39m
+#> 15.0 [31m⡇[39m [32m⠂[39m [34m⡇[39m group
+#> [31m⡇[39m [32m⠂[39m [34m⢰[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⠓[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⢲[39m [31m*[39m Group 1
+#> V [31m⢀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣇[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⡀[39m [32m⠉[39m[32m⠉[39m[32m⡏[39m[32m⠉[39m[32m⠁[39m [34m⢸[39m [34m⢸[39m [35m⢀[39m[35m⣀[39m[35m⣀[39m[35m⣀[39m[35m⣀[39m [33m*[39m Group 2
+#> a [31m⢸[39m [31m⡇[39m [32m⡇[39m [34m⢸[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⢹[39m [35m⢸[39m [32m*[39m Group 3
+#> l 10.0 [31m⢸[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⡇[39m [32m⡇[39m [36m⠐[39m[36m⠒[39m[36m⢲[39m[36m⠒[39m[36m⠒[39m [34m⠘[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⡖[39m[34m⠒[39m[34m⠒[39m[34m⠒[39m[34m⠚[39m [35m⢸[39m [36m*[39m Group 4
+#> u [31m⠸[39m[31m⠤[39m[31m⠤[39m[31m⠤[39m[31m⠤[39m[31m⡤[39m[31m⠤[39m[31m⠤[39m[31m⠤[39m[31m⠇[39m [33m⠠[39m[33m⠤[39m[33m⢤[39m[33m⠤[39m[33m⠤[39m [32m⢰[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠓[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⢲[39m [36m⢸[39m [34m⡇[39m [35m⢰[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠚[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⡆[39m [34m*[39m Group 5
+#> e [31m⡇[39m [33m⣀[39m[33m⣀[39m[33m⣀[39m[33m⣀[39m[33m⣸[39m[33m⣀[39m[33m⣀[39m[33m⣀[39m[33m⣀[39m[33m⡀[39m [32m⢸[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⢺[39m [36m⡖[39m[36m⠒[39m[36m⠒[39m[36m⠒[39m[36m⠚[39m[36m⠒[39m[36m⠒[39m[36m⠒[39m[36m⠒[39m[36m⡆[39m [34m⡇[39m [35m⢸[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⡇[39m [35m*[39m Group 6
+#> 5.0 [31m⡇[39m [33m⡗[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⠒[39m[33m⡇[39m [32m⠘[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⡖[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠚[39m [36m⣏[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⣉[39m[36m⡇[39m [34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠉[39m[34m⠁[39m [35m⠘[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⢲[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠒[39m[35m⠃[39m
+#> [31m⡇[39m [33m⠧[39m[33m⠤[39m[33m⠤[39m[33m⠤[39m[33m⢤[39m[33m⠤[39m[33m⠤[39m[33m⠤[39m[33m⠤[39m[33m⠇[39m [32m⡇[39m [36m⢸[39m [35m⢸[39m
+#> [31m⠤[39m[31m⠤[39m[31m⡧[39m[31m⠤[39m[31m⠄[39m [33m⢀[39m[33m⣀[39m[33m⣸[39m[33m⣀[39m[33m⣀[39m [32m⡇[39m [36m⠠[39m[36m⠤[39m[36m⠼[39m[36m⠤[39m[36m⠤[39m [35m⢸[39m
+#> [32m⠒[39m[32m⠒[39m[32m⠓[39m[32m⠒[39m[32m⠂[39m [35m⠐[39m[35m⠒[39m[35m⠚[39m[35m⠒[39m[35m⠒[39m
+#> 0 [32m⠄[39m
+#> [33m⠈[39m
+#> Group 1 Group 2 Group 3 Group 4 Group 5 Group 6
+#> Group
+#> # Histogram with density overlay
+p <- ggplot(mtcars, aes(x = mpg)) +
+ geom_histogram(aes(y = after_stat(density)), bins = 10, fill = "gray") +
+ geom_density(color = "red") +
+ labs(title = "Histogram with Density Overlay")
+ggplotcli(p, width = 60, height = 12)
+#>
+#> Histogram with Density Overlay
+#> d [35m⢰[39m[35m⣶[39m[35m⣶[39m[35m⣶[39m[35m⣶[39m[35m⣶[39m
+#> e 0.08 [35m⢸[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣶[39m[31m⣶[39m[31m⣶[39m[31m⣶[39m[31m⣶[39m[35m⣶[39m[35m⣶[39m[35m⣶[39m[35m⣶[39m
+#> n 0.06 [35m⢸[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m
+#> s [31m⢀[39m[31m⡴[39m[31m⢻[39m[31m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[31m⣿[39m[31m⠑[39m[31m⢦[39m[31m⡀[39m
+#> i 0.04 [31m⢀[39m[31m⡴[39m[31m⠋[39m [35m⢸[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣤[39m[35m⣤[39m[31m⣭[39m[31m⣷[39m[31m⣤[39m[31m⡀[39m [35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m
+#> t 0.02 [35m⢠[39m[35m⣤[39m[31m⣤[39m[31m⣤[39m[31m⣾[39m[31m⣥[39m[35m⣤[39m[35m⣤[39m[35m⣤[39m[35m⣼[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[31m⣭[39m[31m⣷[39m[31m⣦[39m[31m⣤[39m[31m⣄[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣀[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[35m⣿[39m
+#> y [35m⢸[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⣿[39m[35m⡇[39m [35m⣿[39m[35m⣿[39m[35m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣽[39m[31m⣶[39m[31m⣦[39m[35m⣤[39m[35m⡄[39m
+#> 0 [35m⠸[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠧[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠤[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠿[39m[35m⠇[39m
+#> 10.0 15.0 20.0 25.0 30.0 35.0
+#> mpg
+#> # Points with smooth line
+p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
+ geom_point(color = "gray") +
+ geom_smooth(method = "loess", color = "red") +
+ labs(title = "Scatter with LOESS Smooth")
+suppressMessages(ggplotcli(p, width = 60, height = 12))
+#>
+#> Scatter with LOESS Smooth
+#>
+#> 35.0 [31m⢐[39m[31m⢤[39m[31m⣀[39m[31m⣀[39m[36m⠁[39m [36m⠐[39m
+#> m 30.0 [31m⠉[39m[31m⠲[39m[31m⠢[39m[31m⢄[39m[31m⡀[39m
+#> p 25.0 [31m⠉[39m[31m⠉[39m[31m⡒[39m[31m⠤[39m[31m⣀[39m[31m⣀[39m [36m⡐[39m
+#> g 20.0 [36m⠈[39m [36m⠐[39m[31m⠉[39m[31m⠩[39m[31m⠙[39m[31m⠒[39m[31m⠒[39m[31m⠢[39m[31m⠬[39m[31m⢄[39m[31m⣀[39m[31m⣠[39m [36m⠠[39m
+#> 15.0 [36m⠄[39m [31m⢈[39m[31m⠩[39m[31m⡒[39m[31m⠒[39m[31m⢣[39m[31m⠤[39m[31m⠤[39m[31m⢄[39m[31m⣂[39m[31m⣀[39m[31m⣀[39m [36m⡀[39m
+#> 10.0 [36m⠁[39m [31m⠉[39m[31m⠉[39m[31m⠉[39m[31m⠉[39m[31m⠑[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠒[39m[31m⠢[39m[31m⠤[39m[31m⡤[39m[31m⠤[39m[31m⡄[39m
+#>
+#> 2.0 3.0 4.0 5.0
+#> wt
+#> Faceting works seamlessly with color/fill aesthetics and legends:
+mtcars$cyl_fac <- factor(mtcars$cyl)
+p <- ggplot(mtcars, aes(x = wt, y = mpg, color = cyl_fac)) +
+ geom_point() +
+ facet_wrap(~cyl_fac) +
+ labs(title = "MPG vs Weight: Faceted by Cylinders")
+ggplotcli(p, width = 75, height = 16)
+#>
+#> MPG vs Weight: Faceted by Cylinders
+#> 4, 1 6, 1 8, 1
+#> [31m⠠[39m
+#> [31m⣀[39m [31m⠁[39m
+#> 30.0 cyl_fac
+#> [31m⠁[39m[31m⠄[39m [31m*[39m 4
+#> m [31m⡀[39m [31m⢀[39m[31m⠁[39m [36m*[39m 6
+#> p 20.0 [31m⠈[39m [31m⠂[39m [36m⠂[39m[36m⡐[39m [36m⠂[39m [35m*[39m 8
+#> g [36m⠅[39m [35m⠂[39m[35m⢀[39m[35m⠁[39m
+#> [35m⠂[39m[35m⢤[39m[35m⠠[39m [35m⠁[39m [35m⡀[39m
+#> [35m⠂[39m
+#> 10.0 [35m⠐[39m[35m⠐[39m
+#> 2.0 4.0 2.0 4.0 2.0 4.0
+#>
+#> wt
+#> p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(gear))) +
+ geom_point() +
+ facet_grid(am ~ cyl) +
+ labs(title = "MPG: AM (rows) x Cylinders (cols)")
+ggplotcli(p, width = 80, height = 20)
+#>
+#> MPG: AM (rows) x Cylinders (cols)
+#> 0, 4, 1 0, 6, 1 0, 8, 1
+#>
+#> 30.0
+#> [36m⢀[39m[36m⠂[39m
+#> 20.0 [31m⠁[39m [31m⠁[39m[36m⡄[39m [31m⡀[39m [31m⠄[39m
+#> [31m⠔[39m[31m⠌[39m[31m⡄[39m[31m⠐[39m [31m⠄[39m factor(gear)
+#> m 10.0 [31m⠠[39m[31m⠠[39m [31m*[39m 3
+#> p 1, 4, 1 1, 6, 1 1, 8, 1 [36m*[39m 4
+#> g [36m⠐[39m [36m⠠[39m [35m*[39m 5
+#> 30.0 [35m⠉[39m [36m⡀[39m
+#> [35m⠈[39m[36m⡀[39m
+#> 20.0 [36m⠈[39m [35m⠢[39m[36m⠂[39m
+#> [35m⠐[39m [35m⠄[39m
+#> 10.0
+#> 2.0 4.0 2.0 4.0 2.0 4.0
+#>
+#> wt
+#>
+#> p <- ggplot(mtcars, aes(x = hp, y = qsec)) +
+ geom_point(color = "cyan") +
+ labs(title = "Quarter Mile Time vs HP")
+
+# With border
+ggplotcli(p, width = 55, height = 12, border = TRUE)
+#>
+#> Quarter Mile Time vs HP
+#> ⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹
+#> 22.0 ⡇ [36m⠠[39m ⢸
+#> q ⡇ ⢸
+#> s 20.0 ⡇ [36m⢲[39m [36m⠂[39m[36m⠡[39m [36m⢀[39m ⢸
+#> e 18.0 ⡇ [36m⠈[39m [36m⠁[39m [36m⢈[39m [36m⠈[39m [36m⡀[39m [36m⢀[39m[36m⠰[39m [36m⠂[39m[36m⠐[39m [36m⠠[39m ⢸
+#> c ⡇ [36m⠁[39m [36m⠐[39m[36m⠁[39m [36m⠁[39m [36m⢀[39m [36m⢠[39m ⢸
+#> 16.0 ⡇ [36m⠂[39m [36m⠂[39m ⢸
+#> ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
+#> 50.0 100 150 200 250 300
+#> hp
+#>
+
+# With grid
+ggplotcli(p, width = 55, height = 12, grid = "major")
+#>
+#> Quarter Mile Time vs HP
+#> [90m⡇[39m [36m⠐[39m[90m⢸[39m [90m⡇[39m [90m⡇[39m [90m⢸[39m [90m⡇[39m
+#> 22.0 [90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⢹[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⢹[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m
+#> q [90m⣀[39m[90m⣀[39m[90m⣇[39m[36m⣀[39m[36m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[36m⣸[39m[36m⣄[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣇[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣇[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣸[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣇[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m[90m⣀[39m
+#> s 20.0 [90m⡇[39m [36m⡂[39m [90m⢸[39m [36m⠂[39m[36m⢀[39m [90m⡇[39m [90m⡇[39m [90m⢸[39m [90m⡇[39m
+#> e 18.0 [90m⠤[39m[90m⠤[39m[36m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[36m⠥[39m[90m⢼[39m[36m⠬[39m[90m⠤[39m[36m⠴[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[36m⡤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[36m⠤[39m[36m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m
+#> c [90m⡇[39m [36m⠄[39m[90m⢸[39m [36m⡆[39m [36m⡇[39m [36m⠐[39m[36m⠁[39m [90m⡇[39m [36m⠈[39m [90m⢸[39m [90m⡇[39m
+#> 16.0 [90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[36m⠲[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[36m⣺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m
+#> [90m⡇[39m [90m⢸[39m [90m⡇[39m [90m⡇[39m [90m⢸[39m [36m⠄[39m [90m⡇[39m [36m⠐[39m
+#> 50.0 100 150 200 250 300
+#> hp
+#>
+
+# Both
+ggplotcli(p, width = 55, height = 12, border = TRUE, grid = "major")
+#>
+#> Quarter Mile Time vs HP
+#> ⡏⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉⠉⠉⢹
+#> 22.0 ⡇ [90m⡇[39m [36m⠠[39m[90m⡇[39m [90m⡇[39m [90m⡇[39m [90m⡇[39m [90m⡇[39m ⢸
+#> q [90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⡏[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⠉[39m[90m⢹[39m
+#> s 20.0 [90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[36m⢲[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[36m⡗[39m[36m⠳[39m[90m⠒[39m[36m⢒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> e 18.0 [90m⡗[39m[90m⠒[39m[90m⠒[39m[36m⡟[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[36m⠓[39m[90m⡗[39m[36m⢚[39m[90m⠒[39m[36m⠚[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[36m⡗[39m[90m⠒[39m[90m⠒[39m[36m⢒[39m[36m⠲[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[36m⠒[39m[36m⠒[39m[90m⠒[39m[36m⠲[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> c [90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[36m⠥[39m[90m⡧[39m[36m⠴[39m[36m⠥[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[36m⡧[39m[90m⠤[39m[90m⠤[39m[36m⢤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[36m⢤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m
+#> 16.0 ⡇ [90m⡇[39m [90m⡇[39m [90m⡇[39m [90m⡇[39m [90m⡇[39m [36m⠂[39m [90m⡇[39m [36m⠂[39m ⢸
+#> ⣇⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀⣀⣀⣸
+#> 50.0 100 150 200 250 300
+#> hp
+#> ggplotcli automatically respects ggplot2 themes:
+p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
+ geom_point(color = "blue") +
+ labs(title = "theme_bw() - Grid + Border")
+
+# theme_bw has both grid and border
+ggplotcli(p + theme_bw(), width = 60, height = 14, border = "auto", grid = "auto")
+#>
+#> theme_bw() - Grid + Border
+#> 35.0 ⡏⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⢹
+#> [90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[34m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m
+#> 30.0 [90m⣏[39m[90m⣉[39m[90m⣉[39m[34m⣹[39m[90m⣉[39m[34m⣍[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[34m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m
+#> m [90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[34m⣲[39m[90m⣗[39m[90m⣒[39m[34m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m
+#> p 25.0 [90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[34m⡒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[34m⡒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> g 20.0 [90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[34m⠭[39m[90m⡯[39m[34m⠯[39m[90m⠭[39m[34m⠭[39m[34m⠯[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[34m⠭[39m[90m⠭[39m[34m⢭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[34m⡭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m
+#> [90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[34m⢭[39m[90m⠭[39m[90m⠭[39m[34m⢭[39m[34m⣯[39m[90m⠭[39m[34m⠽[39m[34m⢭[39m[90m⠭[39m[90m⢽[39m[34m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m
+#> 15.0 [90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[34m⣓[39m[90m⣒[39m[90m⣒[39m[34m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[34m⣓[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m
+#> [90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[34m⠒[39m[90m⠒[39m[34m⢺[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> 10.0 ⣇⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣸
+#> 2.0 3.0 4.0 5.0
+#> wt
+#>
+
+# theme_classic has border but no grid
+ggplotcli(p + theme_classic() + labs(title = "theme_classic() - Border Only"),
+ width = 60, height = 14, border = "auto", grid = "auto")
+#>
+#> theme_classic() - Border Only
+#> 35.0 ⡏⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⢹[39m⠉⠉⠉⠉⠉[90m⡏[39m⠉⠉⠉⠉[90m⢹[39m⠉⠉⢹
+#> [90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[34m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⡧[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m[90m⠤[39m[90m⠤[39m[90m⢼[39m
+#> 30.0 [90m⣏[39m[90m⣉[39m[90m⣉[39m[34m⣹[39m[90m⣉[39m[34m⣍[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[34m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣏[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m[90m⣉[39m[90m⣉[39m[90m⣹[39m
+#> m [90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[34m⣲[39m[90m⣗[39m[90m⣒[39m[34m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m
+#> p 25.0 [90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[34m⡒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[34m⡒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> g 20.0 [90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[34m⠭[39m[90m⡯[39m[34m⠯[39m[90m⠭[39m[34m⠭[39m[34m⠯[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[34m⠭[39m[90m⠭[39m[34m⢭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[34m⡭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m
+#> [90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[34m⢭[39m[90m⠭[39m[90m⠭[39m[34m⢭[39m[34m⣯[39m[90m⠭[39m[34m⠽[39m[34m⢭[39m[90m⠭[39m[90m⢽[39m[34m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⡯[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m[90m⠭[39m[90m⠭[39m[90m⢽[39m
+#> 15.0 [90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[34m⣓[39m[90m⣒[39m[90m⣒[39m[34m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[90m⣗[39m[90m⣒[39m[90m⣒[39m[90m⣒[39m[34m⣓[39m[90m⣺[39m[90m⣒[39m[90m⣒[39m[90m⣺[39m
+#> [90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⠒[39m[90m⡗[39m[90m⠒[39m[90m⠒[39m[34m⠒[39m[90m⠒[39m[34m⢺[39m[90m⠒[39m[90m⠒[39m[90m⢺[39m
+#> 10.0 ⣇⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣸[39m⣀⣀⣀⣀⣀[90m⣇[39m⣀⣀⣀⣀[90m⣸[39m⣀⣀⣸
+#> 2.0 3.0 4.0 5.0
+#> wt
+#> Three rendering modes are available:
+wave <- ggplot(data.frame(x = 1:25, y = sin(1:25/4)*8), aes(x, y)) +
+ geom_line(color = "green")
+
+# Braille (highest resolution - 2x4 dots per character)
+ggplotcli(wave + labs(title = "Braille Canvas (highest resolution)"),
+ width = 50, height = 8, canvas_type = "braille")
+#>
+#> Braille Canvas (highest resolution)
+#> [32m⢀[39m[32m⣀[39m[32m⠤[39m[32m⠔[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠒[39m[32m⠤[39m[32m⢄[39m[32m⡀[39m
+#> y 5.0 [32m⠔[39m[32m⠊[39m[32m⠁[39m [32m⠈[39m[32m⠑[39m[32m⠤[39m[32m⣀[39m
+#> -5.0 [32m⠉[39m[32m⠑[39m[32m⠢[39m[32m⢄[39m[32m⡀[39m [32m⣀[39m[32m⠤[39m[32m⠒[39m[32m⠉[39m
+#> [32m⠈[39m[32m⠑[39m[32m⠢[39m[32m⠤[39m[32m⠤[39m[32m⠤[39m[32m⠤[39m[32m⠤[39m[32m⠤[39m[32m⠒[39m[32m⠊[39m[32m⠉[39m
+#> 0 5.0 10.0 15.0 20.0 25.0
+#> x
+#>
+
+# Block (medium resolution - uses block characters)
+ggplotcli(wave + labs(title = "Block Canvas (medium resolution)"),
+ width = 50, height = 8, canvas_type = "block")
+#>
+#> Block Canvas (medium resolution)
+#> [32m▄[39m[32m▄[39m[32m▄[39m[32m▀[39m[32m▀[39m[32m▀[39m[32m▀[39m[32m▀[39m[32m▄[39m[32m▄[39m[32m▄[39m
+#> y 5.0 [32m▄[39m[32m▀[39m[32m▀[39m [32m▀[39m[32m▀[39m[32m▀[39m[32m▄[39m[32m▄[39m
+#> -5.0 [32m▀[39m[32m▄[39m[32m▄[39m[32m▄[39m [32m▄[39m[32m▄[39m[32m▀[39m[32m▀[39m
+#> [32m▀[39m[32m▀[39m[32m▀[39m[32m▄[39m[32m▄[39m[32m▄[39m[32m▄[39m[32m▄[39m[32m▀[39m[32m▀[39m[32m▀[39m
+#> 0 5.0 10.0 15.0 20.0 25.0
+#> x
+#>
+
+# ASCII (basic, most compatible)
+ggplotcli(wave + labs(title = "ASCII Canvas (most compatible)"),
+ width = 50, height = 8, canvas_type = "ascii")
+#>
+#> ASCII Canvas (most compatible)
+#> [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m
+#> y 5.0 [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m
+#> -5.0 [32m*[39m[32m*[39m[32m*[39m[32m*[39m [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m
+#> [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m
+#> 0 5.0 10.0 15.0 20.0 25.0
+#> x
+#> ggplotcli intelligently maps ggplot2 colors to terminal colors (red, +yellow, green, cyan, blue, magenta). The mapping prioritizes +color distinctness over hue accuracy to maximize visual +differentiation between groups.
+Even with many groups, colors are distributed to minimize +repetition:
+set.seed(123)
+df <- data.frame(
+ group = factor(rep(paste0("G", 1:8), each = 30)),
+ value = unlist(lapply(1:8, function(i) rnorm(30, mean = i * 2, sd = 1.5)))
+)
+p <- ggplot(df, aes(x = group, y = value, fill = group)) +
+ geom_boxplot() +
+ labs(title = "8 Groups with Optimized Color Distribution")
+ggplotcli(p, width = 85, height = 18, boxplot_style = "ascii")
+#>
+#> 8 Groups with Optimized Color Distribution
+#> [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m
+#> [35m*[39m [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [33m┌[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┐[39m group
+#> [35m*[39m [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m [33m└[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┘[39m [31m*[39m G1
+#> 15.0 [35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m [31m│[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m│[39m [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m [33m*[39m G2
+#> v [34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m [35m┌[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m┐[39m [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m [32m*[39m G3
+#> a [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [34m┌[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m┐[39m [35m└[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m─[39m[35m┘[39m [36m*[39m G4
+#> l 10.0 [32m*[39m [36m┌[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┐[39m [34m│[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m│[39m [34m*[39m G5
+#> u [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [36m└[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┘[39m [34m└[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m─[39m[34m┘[39m [35m*[39m G6
+#> e [33m│[39m [32m└[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┘[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [31m*[39m G7
+#> 5.0 [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [33m┌[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┐[39m [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [33m*[39m G8
+#> [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m [33m└[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m┘[39m [32m*[39m
+#> [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m [33m─[39m[33m─[39m[33m─[39m[33m─[39m[33m─[39m
+#> 0 [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m
+#>
+#> G1 G2 G3 G4 G5 G6 G7 G8
+#> group
+#> set.seed(42)
+df <- data.frame(
+ treatment = factor(rep(c("Control", "Drug A", "Drug B"), each = 60)),
+ timepoint = factor(rep(rep(c("Baseline", "Week 4", "Week 8"), each = 20), 3)),
+ response = c(
+ rnorm(20, 50, 10), rnorm(20, 52, 10), rnorm(20, 51, 10), # Control
+ rnorm(20, 50, 10), rnorm(20, 65, 12), rnorm(20, 70, 11), # Drug A
+ rnorm(20, 50, 10), rnorm(20, 58, 11), rnorm(20, 62, 10) # Drug B
+ )
+)
+
+p <- ggplot(df, aes(x = timepoint, y = response)) +
+ geom_boxplot(aes(fill = treatment)) +
+ labs(title = "Treatment Response Over Time",
+ subtitle = "Faceted by treatment group",
+ x = "Timepoint", y = "Response") +
+ theme_bw()
+
+ggplotcli(p, width = 100, height = 22, boxplot_style = "ascii")
+#>
+#> Treatment Response Over Time
+#> Faceted by treatment group
+#> ⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹
+#> 100 ⡇ [32m*[39m ⢸
+#> ⡇ ⢸
+#> ⡇ [32m*[39m ⢸
+#> R 80.0 ⡇ [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [32m─[39m[32m─[39m[32m*[39m[32m─[39m[32m─[39m ⢸
+#> e ⡇ [32m┌[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┐[39m [32m│[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m ⢸ treatment
+#> s ⡇ [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [32m│[39m [32m│[39m [36m*[39m [32m┌[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┐[39m[36m┌[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┐[39m ⢸ [31m*[39m Control
+#> p ⡇ [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [31m│[39m [32m│[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m│[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [32m└[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┘[39m[36m│[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m│[39m ⢸ [32m*[39m Drug A
+#> o 60.0 ⡇ [31m│[39m [31m│[39m[32m┌[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┐[39m [36m│[39m [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m[32m└[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┘[39m[36m┌[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┐[39m [31m┌[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┐[39m [32m│[39m [36m└[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┘[39m ⢸ [36m*[39m Drug B
+#> n ⡇ [31m│[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m│[39m[32m│[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m│[39m[36m┌[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┐[39m [31m│[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m│[39m [32m│[39m [36m└[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┘[39m [31m│[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m│[39m [32m─[39m[32m─[39m[32m*[39m[32m─[39m[32m─[39m [36m│[39m ⢸
+#> s ⡇ [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m[32m└[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m┘[39m[36m│[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m│[39m [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [31m└[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m┘[39m [36m─[39m[36m─[39m[36m*[39m[36m─[39m[36m─[39m ⢸
+#> e ⡇ [31m│[39m [32m─[39m[32m─[39m[32m─[39m[32m─[39m[32m─[39m [36m└[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m┘[39m [31m│[39m [36m*[39m [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m ⢸
+#> 40.0 ⡇ [31m│[39m [36m│[39m [31m│[39m ⢸
+#> ⡇ [31m│[39m [36m─[39m[36m─[39m[36m─[39m[36m─[39m[36m─[39m [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m ⢸
+#> ⡇ [31m─[39m[31m─[39m[31m─[39m[31m─[39m[31m─[39m [31m*[39m ⢸
+#> 20.0 ⡇ ⢸
+#> ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
+#> Baseline Week 4 Week 8
+#> Timepoint
+#> # Simulated experiment data
+set.seed(123)
+x <- seq(0, 10, length.out = 50)
+df <- data.frame(
+ x = rep(x, 3),
+ y = c(
+ 2 * x + rnorm(50, 0, 1.5),
+ 1.5 * x + 3 + rnorm(50, 0, 1.2),
+ x^1.2 + rnorm(50, 0, 1)
+ ),
+ group = rep(c("Linear", "Offset", "Power"), each = 50)
+)
+
+p <- ggplot(df, aes(x = x, y = y, color = group)) +
+ geom_point(alpha = 0.6) +
+ geom_smooth(method = "loess", se = FALSE) +
+ labs(title = "Multi-Group Regression Analysis",
+ subtitle = "Points with LOESS smoothing",
+ x = "Predictor", y = "Response") +
+ theme_minimal()
+
+suppressMessages(ggplotcli(p, width = 70, height = 18))
+#>
+#> Multi-Group Regression Analysis
+#> Points with LOESS smoothing
+#> [31m⠄[39m [31m⠠[39m
+#> 20.0 [31m⠂[39m[31m⢀[39m[31m⡐[39m[31m⣤[39m[31m⢰[39m[31m⣾[39m
+#> R [31m⡀[39m[31m⣠[39m[31m⡄[39m[31m⣶[39m[31m⢰[39m[31m⣇[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m
+#> e 15.0 [31m⢀[39m[31m⢀[39m[31m⠠[39m[31m⡀[39m[31m⣤[39m[31m⣠[39m[31m⣾[39m[31m⣸[39m[31m⣯[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⡟[39m[31m⣿[39m[31m⢹[39m[31m⠿[39m group
+#> s [31m⠂[39m[31m⡀[39m[31m⡀[39m[31m⣬[39m[31m⢰[39m[31m⣾[39m[31m⣸[39m[31m⣧[39m[31m⣿[39m[31m⣾[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⡟[39m[31m⣿[39m[31m⠹[39m[31m⠇[39m[31m⠛[39m[31m⢁[39m[31m⠁[39m [36m⠈[39m [31m*[39m Linear
+#> p [32m⢀[39m [32m⡀[39m [32m⠐[39m[31m⠐[39m[31m⣀[39m[31m⣠[39m[31m⢠[39m[31m⣦[39m[31m⣿[39m[31m⣷[39m[31m⣿[39m[31m⣿[39m[31m⣿[39m[31m⢿[39m[31m⡟[39m[31m⣿[39m[31m⢻[39m[31m⠿[39m[31m⠸[39m[31m⠃[39m[31m⠋[39m[31m⠡[39m [36m⠂[39m[36m⠁[39m [32m*[39m Offset
+#> o 10.0 [32m⠠[39m [31m⡀[39m[31m⣠[39m[31m⢠[39m[31m⣴[39m[31m⢴[39m[31m⡇[39m[31m⣿[39m[31m⣷[39m[31m⣿[39m[31m⣿[39m[31m⡟[39m[31m⣿[39m[31m⡏[39m[31m⡿[39m[31m⢸[39m[31m⠛[39m[31m⠘[39m[31m⠁[39m[31m⡁[39m [36m⠈[39m [36m*[39m Power
+#> n [31m⡀[39m[31m⣥[39m[31m⡆[39m[31m⣶[39m[31m⢰[39m[31m⣿[39m[31m⢸[39m[31m⡇[39m[31m⣿[39m[31m⣸[39m[31m⣿[39m[31m⣿[39m[31m⡿[39m[31m⣿[39m[31m⡯[39m[31m⠿[39m[31m⠘[39m[31m⠃[39m[31m⠉[39m [36m⠐[39m
+#> s [32m⡀[39m [32m⠐[39m [31m⢄[39m[31m⣀[39m[31m⢤[39m[31m⡆[39m[31m⣶[39m[31m⣖[39m[31m⣿[39m[31m⢸[39m[31m⡇[39m[31m⣿[39m[31m⣇[39m[31m⣿[39m[31m⣼[39m[31m⣿[39m[31m⢾[39m[31m⡟[39m[31m⡿[39m[31m⡹[39m[31m⠟[39m[31m⠘[39m[31m⠑[39m[31m⠁[39m [36m⠈[39m
+#> e 5.0 [31m⢀[39m[31m⡀[39m[31m⣠[39m[31m⢠[39m[31m⣴[39m[31m⢰[39m[31m⡇[39m[31m⣿[39m[31m⢸[39m[31m⣿[39m[31m⢸[39m[31m⡇[39m[31m⣿[39m[31m⣧[39m[31m⣿[39m[31m⣾[39m[31m⡿[39m[31m⣿[39m[31m⡟[39m[31m⡿[39m[31m⠹[39m[31m⠫[39m[31m⠈[39m [36m⠂[39m
+#> [31m⣿[39m[31m⡇[39m[31m⣿[39m[31m⢸[39m[31m⣿[39m[31m⣸[39m[31m⣿[39m[31m⣿[39m[31m⢾[39m[31m⣿[39m[31m⢻[39m[31m⡟[39m[31m⠿[39m[31m⠃[39m[31m⠛[39m[31m⠈[39m[31m⠁[39m
+#> 0 [31m⣿[39m[31m⡷[39m[31m⣿[39m[31m⠿[39m[31m⢿[39m[31m⠙[39m[31m⠣[39m[31m⠋[39m[31m⡊[39m[31m⠁[39m [36m⠈[39m
+#> [31m⠋[39m
+#> 0 2.0 4.0 6.0 8.0 10.0
+#> Predictor
+#> p <- ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
+ geom_point() +
+ facet_wrap(~Species) +
+ labs(title = "Iris Dataset: Sepal vs Petal Length",
+ subtitle = "Faceted by species with color legend") +
+ theme_bw()
+
+ggplotcli(p, width = 80, height = 16)
+#>
+#> Iris Dataset: Sepal vs Petal Length
+#> Faceted by species with color legend
+#> setosa, 1 versicolor, 1 virginica, 1
+#> P ⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹ ⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹ ⡏⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹
+#> e 6.0⡇ ⢸ ⡇ ⢸ ⡇ [35m⢀[39m[35m⡄[39m ⢸
+#> t ⡇ ⢸ ⡇ ⢸ ⡇ [35m⡀[39m[35m⣄[39m[35m⠄[39m[35m⡤[39m[35m⡀[39m[35m⠴[39m[35m⠑[39m [35m⠂[39m[35m⠁[39m ⢸ Species
+#> a ⡇ ⢸ ⡇ [36m⡀[39m[36m⣀[39m[36m⠠[39m[36m⣂[39m[36m⣄[39m[36m⣀[39m[36m⡢[39m[36m⢄[39m ⢸ ⡇ [35m⢀[39m [35m⠔[39m[35m⠒[39m[35m⠮[39m[35m⠎[39m[35m⠃[39m[35m⠊[39m[35m⠃[39m ⢸ [31m*[39m setosa
+#> l 4.0⡇ ⢸ ⡇ [36m⡀[39m[36m⠄[39m[36m⠸[39m[36m⣖[39m[36m⠖[39m[36m⠊[39m[36m⠉[39m[36m⠈[39m[36m⠁[39m ⢸ ⡇ ⢸ [36m*[39m versicolor
+#> . ⡇ ⢸ ⡇ [36m⠈[39m[36m⠑[39m ⢸ ⡇ ⢸ [35m*[39m virginica
+#> L 2.0⡇ [31m⡀[39m[31m⣀[39m[31m⣂[39m[31m⣰[39m[31m⣀[39m[31m⣄[39m[31m⢠[39m ⢸ ⡇ ⢸ ⡇ ⢸
+#> e ⡇ [31m⠈[39m[31m⠉[39m[31m⠊[39m [31m⠁[39m [31m⠉[39m [31m⠁[39m ⢸ ⡇ ⢸ ⡇ ⢸
+#> n ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸ ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸ ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣸
+#> g 5.0 6.0 7.0 8.0 5.0 6.0 7.0 8.0 5.0 6.0 7.0 8.0
+#>
+#> Sepal.Length
+#> | Feature | +Status | +
|---|---|
| geom_point | +✓ | +
| geom_line, geom_path | +✓ | +
| geom_bar, geom_col, geom_histogram | +✓ | +
| geom_density | +✓ | +
| geom_smooth | +✓ | +
| geom_area | +✓ | +
| geom_segment, geom_hline, geom_vline | +✓ | +
| geom_rect | +✓ | +
| geom_text | +✓ | +
| geom_boxplot | +✓ | +
| Color/fill aesthetics | +✓ | +
| Legends (auto-generated) | +✓ | +
| facet_wrap, facet_grid | +✓ | +
| Titles, subtitles, captions | +✓ | +
| Theme auto-detection | +✓ | +
| Optimized color mapping | +✓ | +
| Multiple canvas types | +✓ | +
| geom_tile (heatmaps) | +Planned | +
| geom_violin | +Planned | +
library(plotcli)
+
+plot_width = 80
+plot_height = 40
+
+# Create some example data
+x <- seq(0, 2 * pi, length.out = 100)
+y1 <- sin(x)
+y2 <- cos(x)
+
+data_1 = list(
+ x = x,
+ y = y1,
+ name = "y1 = sin(x)",
+ color = "blue",
+ type = "line",
+ braille = FALSE
+ )
+
+data_2 = list(
+ x = x,
+ y = y2,
+ name = "y2 = cos(x)",
+ color = "red",
+ type = "line",
+ braille = FALSE
+ )
+
+# Create a plotcli object with specified dimensions
+plot <- plotcli$new(
+ plot_width = plot_width,
+ plot_height = plot_height,
+ x_label = "X-axis",
+ y_label = "Y-axis"
+ )
+
+# Add data sets to the plot
+plot$add_data(data_1)
+plot$add_data(data_2)
+
+# Print the plot
+plot$print_plot()
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────────────────────────┐
+#> 1.0 │[31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m [34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m [31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m│
+#> │ [31m*[39m [34m*[39m[34m*[39m [34m*[39m[34m*[39m [31m*[39m │
+#> │ [31m*[39m[31m*[39m [34m*[39m [34m*[39m [31m*[39m[31m*[39m │
+#> │ [31m*[39m [34m*[39m[34m*[39m [34m*[39m [31m*[39m │
+#> │ [31m*[39m [34m*[39m [34m*[39m [31m*[39m │
+#> │ [31m*[39m[31m*[39m [34m*[39m [31m*[39m[31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> 0.5 │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │
+#> │ [34m*[39m [31m*[39m [34m*[39m [31m*[39m │ [34my1 = sin(x)[39m
+#> Y-axis 0.0 │[34m*[39m [31m*[39m [34m*[39m [31m*[39m [34m*[39m│ [31my2 = cos(x)[39m
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m│
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> -0.5 │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [34m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [31m*[39m [34m*[39m │
+#> │ [31m*[39m [31m*[39m [34m*[39m [34m*[39m │
+#> │ [31m*[39m [31m*[39m [34m*[39m [34m*[39m[34m*[39m │
+#> │ [31m*[39m [31m*[39m [34m*[39m [34m*[39m │
+#> │ [31m*[39m[31m*[39m [31m*[39m[31m*[39m [34m*[39m[34m*[39m [34m*[39m[34m*[39m │
+#> │ [31m*[39m [31m*[39m [34m*[39m[34m*[39m [34m*[39m[34m*[39m[34m*[39m │
+#> -1.0 │ [31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m[31m*[39m [34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m[34m*[39m │
+#> └────────────────────────────────────────────────────────────────────────────────┘
+#>
+#> 0.0 1.6 3.1 4.7 6.3
+#>
+#> X-axis
+#> plotcli can use braille characters for plotting scatter and line +plots, which give a much higher resolution on supported terminals. +Whether to use braille or ascii characters can be specified for each +data set.
+library(plotcli)
+
+data(mtcars)
+
+# Fit a linear model
+lm_fit <- lm(wt ~ mpg, data = mtcars)
+
+# Create a new dataset with the predicted values
+predicted_data <- data.frame(mpg = mtcars$mpg, predicted_wt = predict(lm_fit, mtcars))
+
+# we use braille characters for the regression line
+data_1 = list(
+ x = predicted_data$mpg,
+ y = predicted_data$predicted_wt,
+ name = "Regression Line",
+ color = "red",
+ type = "line",
+ braille = TRUE
+ )
+
+# and ascii characters for the raw data
+data_2 = list(
+ x = mtcars$mpg,
+ y = mtcars$wt,
+ name = "Data Points",
+ color = "blue",
+ type = "scatter",
+ braille = FALSE
+ )
+
+# Create a plotcli object
+plot_width = 80
+plot_height = 40
+plot_obj <- plotcli$new(
+ plot_width,
+ plot_height,
+ x_label = "Miles per Gallon",
+ y_label = "Weight"
+ )
+
+# Add raw data and regression line
+plot_obj$add_data(data_1)
+plot_obj$add_data(data_2)
+
+# Print the plot
+plot_obj$print_plot()
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────────────────────────┐
+#> 5.4 │[34m*[39m [34m*[39m │
+#> │[34m*[39m │
+#> │ │
+#> │ │
+#> │ │
+#> │ │
+#> │ │
+#> │[31m⡀[39m │
+#> │[31m⠈[39m[31m⠒[39m[31m⢄[39m │
+#> │ [31m⠑[39m[31m⠦[39m[31m⡀[39m │
+#> 4.4 │ [31m⠈[39m[31m⠳[39m[31m⣄[39m │
+#> │ [31m⠙[39m[31m⢦[39m[31m⡀[39m │
+#> │ [31m⠉[39m[31m⠳[39m[31m⣄[39m[31m⡀[39m [34m*[39m │
+#> │ [31m⠈[39m[31m⠛[39m[31m⢦[39m[31m⣀[39m │
+#> │ [34m*[39m [31m⠙[39m[31m⠳[39m[31m⣄[39m [34m*[39m │
+#> │ [34m*[39m[31m⠈[39m[31m⠛[39m[31m⢦[39m[31m⡀[39m [34m*[39m │
+#> │ [31m⠙[39m[31m⠲[39m[31m⣄[39m │
+#> │ [34m*[39m [34m*[39m[34m*[39m [31m⠈[39m[31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [34m*[39m [34m*[39m[34m*[39m[31m⣄[39m[34m*[39m [34m*[39m │ [31mRegression Line[39m
+#> Weight 3.3 │ [31m⠈[39m[31m⠙[39m[31m⢦[39m[31m⣀[39m │ [34mData Points[39m
+#> │ [31m⠉[39m[31m⠳[39m[31m⣄[39m [34m*[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠙[39m[31m⢦[39m[31m⡀[39m [34m*[39m [34m*[39m │
+#> │ [31m⠉[39m[31m⠲[39m[31m⣄[39m │
+#> │ [31m⠈[39m[31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [34m*[39m[34m*[39m [31m⠙[39m[31m⠲[39m[31m⣄[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠲[39m[31m⣄[39m │
+#> │ [31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠲[39m[31m⣄[39m │
+#> 2.3 │ [34m*[39m [31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [31m⠈[39m[31m⠲[39m[31m⣄[39m [34m*[39m │
+#> │ [34m*[39m [31m⠑[39m[31m⢤[39m[31m⡀[39m │
+#> │ [31m⠉[39m[31m⠢[39m[31m⣄[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠑[39m[31m⢤[39m[31m⡀[39m │
+#> │ [31m⠉[39m[31m⠢[39m[31m⣄[39m [34m*[39m│
+#> │ [31m⠈[39m[31m⠑[39m[31m⢦[39m[31m⡀[39m │
+#> │ [34m*[39m [31m⠉[39m[31m⠲[39m[31m⣄[39m │
+#> │ [34m*[39m [31m⠈[39m[31m⠓[39m[31m⢦[39m[31m⡀[39m │
+#> │ [31m⠙[39m[31m⠢[39m[31m⡀[39m │
+#> 1.3 │ [31m⠈[39m[31m⠒[39m[31m⢄[39m│
+#> └────────────────────────────────────────────────────────────────────────────────┘
+#>
+#> 10.4 16.3 22.1 28.0 33.9
+#>
+#> Miles per Gallon
+#> plotcli convenience wrapperslibrary(plotcli)
+# Generate sample data
+sample_data <- rnorm(1000, mean = 5, sd = 2)
+
+# Create a density plot
+plotcli_density(sample_data, color = "blue", braille = TRUE)
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────┐
+#> 0.2 │ [34m⢀[39m[34m⠞[39m[34m⠉[39m[34m⠉[39m[34m⢣[39m[34m⡀[39m │
+#> │ [34m⢀[39m[34m⡎[39m [34m⢣[39m │
+#> │ [34m⡜[39m [34m⢧[39m │
+#> │ [34m⣰[39m[34m⠁[39m [34m⠈[39m[34m⡆[39m │
+#> │ [34m⢠[39m[34m⠃[39m [34m⠹[39m[34m⡀[39m │
+#> 0.2 │ [34m⡎[39m [34m⢳[39m[34m⡀[39m │
+#> │ [34m⡜[39m [34m⢧[39m │
+#> │ [34m⡸[39m[34m⠁[39m [34m⠈[39m[34m⡆[39m │
+#> │ [34m⡜[39m[34m⠁[39m [34m⠸[39m[34m⡀[39m │
+#> Density 0.1 │ [34m⡜[39m [34m⢇[39m │
+#> │ [34m⡜[39m [34m⠘[39m[34m⡄[39m │
+#> │ [34m⢸[39m[34m⠁[39m [34m⢱[39m │
+#> │ [34m⢠[39m[34m⠇[39m [34m⠈[39m[34m⢇[39m │
+#> │ [34m⢀[39m[34m⠎[39m [34m⠈[39m[34m⢆[39m │
+#> 0.1 │ [34m⢀[39m[34m⡜[39m [34m⠈[39m[34m⢦[39m[34m⡀[39m │
+#> │ [34m⢀[39m[34m⠞[39m [34m⠱[39m[34m⡄[39m │
+#> │ [34m⣠[39m[34m⠋[39m [34m⠙[39m[34m⣆[39m │
+#> │ [34m⢀[39m[34m⡜[39m[34m⠁[39m [34m⠈[39m[34m⠳[39m[34m⣄[39m[34m⡀[39m │
+#> │ [34m⣀[39m[34m⡴[39m[34m⠋[39m [34m⠉[39m[34m⠙[39m[34m⠢[39m[34m⣄[39m │
+#> 0.0 │[34m⣀[39m[34m⣀[39m[34m⣀[39m[34m⣠[39m[34m⠤[39m[34m⠔[39m[34m⠚[39m[34m⠉[39m[34m⠁[39m [34m⠈[39m[34m⠙[39m[34m⠲[39m[34m⠤[39m[34m⠤[39m[34m⠤[39m[34m⣄[39m[34m⣀[39m[34m⣀[39m[34m⣀[39m│
+#> └────────────────────────────────────────────────────────────┘
+#>
+#> -1.9 1.7 5.4 9.1 12.8
+#>
+#> x
+#> # Generate sample data
+sample_data <- rnorm(1000, mean = 5, sd = 2)
+
+# Create a histogram
+plotcli_histogram(sample_data, color = "yellow")
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────┐
+#> 209 │ [33m█[39m │
+#> │ [33m█[39m │
+#> │ [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m │
+#> 157 │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> Frequency 104 │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> 52.2 │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> │ [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m │
+#> 0.0 │[33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m [33m█[39m│
+#> └────────────────────────────────────────────────────────────┘
+#>
+#> -1.5 1.8 5.0 8.2 11.5
+#>
+#> x
+#> # Create a scatter plot
+plotcli_scatter(x = iris$`Sepal.Width`, y = iris$`Sepal.Length`, color = "magenta", braille = FALSE)
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────┐
+#> 7.9 │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m │
+#> │ [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m │
+#> 7.0 │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> y 6.1 │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m│
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> 5.2 │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │[35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> │ [35m*[39m [35m*[39m [35m*[39m [35m*[39m │
+#> 4.3 │ [35m*[39m │
+#> └────────────────────────────────────────────────────────────┘
+#>
+#> 2.0 2.6 3.2 3.8 4.4
+#>
+#> x
+#>
+# make sin
+x <- seq(0, 2*pi, length.out = 50)
+y <- sin(x)
+
+# Create a line plot
+plotcli_line(x = x, y = cos(y), color = "green")
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────┐
+#> 1.0 │[32m*[39m[32m*[39m[32m*[39m [32m*[39m[32m*[39m[32m*[39m[32m*[39m[32m*[39m [32m*[39m[32m*[39m│
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> 0.9 │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> y 0.8 │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> 0.7 │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> │ [32m*[39m [32m*[39m [32m*[39m [32m*[39m │
+#> 0.5 │ [32m*[39m[32m*[39m[32m*[39m[32m*[39m [32m*[39m[32m*[39m[32m*[39m[32m*[39m │
+#> └────────────────────────────────────────────────────────────┘
+#>
+#> 0.0 1.6 3.1 4.7 6.3
+#>
+#> x
+#>
+plotcli_line(x = x, y = x, color = "magenta", braille = FALSE)
+#>
+#>
+#> ┌────────────────────────────────────────────────────────────┐
+#> 6.3 │ [35m*[39m[35m*[39m[35m*[39m[35m*[39m│
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> 4.7 │ [35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m[35m*[39m │
+#> y 3.1 │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> 1.6 │ [35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m[35m*[39m │
+#> │ [35m*[39m[35m*[39m[35m*[39m │
+#> 0.0 │[35m*[39m[35m*[39m │
+#> └────────────────────────────────────────────────────────────┘
+#>
+#> 0.0 1.6 3.1 4.7 6.3
+#>
+#> x
+#> 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()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()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()