Learn R Programming

plotcli (version 0.2.0)

ggplotcli: ggplotcli - Render ggplot2 objects in the terminal

Description

Convert any ggplot2 plot to a terminal-based visualization using Unicode Braille characters or ASCII. Supports 15+ geom types, faceting, themes, and color aesthetics.

Usage

ggplotcli(
  p,
  width = 60,
  height = 20,
  canvas_type = "braille",
  border = "auto",
  grid = "none",
  show_axes = TRUE,
  axis_labels = TRUE,
  legend = "auto",
  title_align = "center",
  subtitle = TRUE,
  caption = TRUE,
  title = NULL,
  boxplot_style = "ascii"
)

Value

Invisibly returns the canvas object

Arguments

p

A ggplot2 object to render

width

Character width of the plot (default: 60)

height

Character height of the plot (default: 20)

canvas_type

Type of canvas: "braille" (high-res), "block" (medium), or "ascii" (basic). Default: "braille"

border

Draw border around plot. "auto" uses ggplot theme, or TRUE/FALSE (default: "auto")

grid

Grid lines: "none", "major", "minor", "both", or "auto" (default: "none")

show_axes

Whether to show axis values (default: TRUE)

axis_labels

Whether to show axis labels from ggplot (default: TRUE)

legend

Legend display: "auto", "right", "bottom", "none" (default: "auto")

title_align

Title alignment: "center" or "left" (default: "center")

subtitle

Whether to show subtitle (default: TRUE)

caption

Whether to show caption (default: TRUE)

title

Optional title override (NULL uses ggplot title)

boxplot_style

Style for boxplots: "ascii" uses box-drawing characters (default), "braille" uses Braille dots like other geoms

Examples

Run this code
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)

Run the code above in your browser using DataLab