Skip to content

cheuerde/plotcli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plotcli: ggplot2 in Your Terminal

CRAN status CRAN checks Downloads Downloads

plotcli: colored scatter plot in terminal

plotcli renders ggplot2 plots directly in the terminal using Unicode Braille characters and ANSI colors. Write your ggplot code as usual, then call ggplotcli() to see it in the console -- no graphics device needed.

Inspired by the excellent UnicodePlots.jl.

Installation

# From CRAN
install.packages("plotcli")

# Development version from GitHub
remotes::install_github("cheuerde/plotcli")

Quick Start

Any ggplot2 plot works. Build your plot as usual, then pass it to ggplotcli():

library(plotcli)
library(ggplot2)

p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
  geom_point() +
  labs(title = "MPG vs Weight by Cylinders",
       x = "Weight (1000 lbs)", y = "Miles per Gallon",
       color = "Cylinders") +
  theme_bw()

ggplotcli(p)

Scatter plot with colored groups

Gallery

Boxplots

p <- ggplot(df, aes(x = group, y = value, fill = group)) +
  geom_boxplot() +
  labs(title = "Distribution Comparison by Group")
ggplotcli(p)

Boxplot

Line Charts

p <- ggplot(economics, aes(x = date, y = unemploy)) +
  geom_line(color = "steelblue") +
  geom_smooth(color = "red", se = FALSE) +
  labs(title = "US Unemployment Over Time")
ggplotcli(p)

Line chart

Bar Charts

Bar chart

Histograms

Histogram

Density Plots

Density plot

Heatmaps

cor_mat <- cor(mtcars[, c("mpg", "cyl", "disp", "hp", "wt", "qsec")])
df <- as.data.frame(as.table(cor_mat))
names(df) <- c("Var1", "Var2", "value")
p <- ggplot(df, aes(Var1, Var2, fill = value)) +
  geom_tile() +
  labs(title = "Correlation Heatmap", fill = "correlation")
ggplotcli(p)

Heatmap

Faceted Plots

p <- ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(color = "steelblue") +
  geom_smooth(method = "lm", color = "red", se = FALSE) +
  facet_wrap(~drv) +
  theme_bw()
ggplotcli(p, width = 80, height = 18)

Faceted plot

Canvas Types

Block canvas -- medium resolution using block characters:

Block canvas

ASCII canvas -- basic ASCII for maximum compatibility:

ASCII canvas

Supported Geoms (27)

Geom Status
geom_point
geom_line, geom_path
geom_step
geom_bar, geom_col, geom_histogram
geom_boxplot
geom_violin
geom_density
geom_smooth
geom_area
geom_ribbon
geom_segment, geom_hline, geom_vline, geom_abline
geom_errorbar, geom_linerange, geom_pointrange, geom_crossbar
geom_rect, geom_tile, geom_raster (heatmaps)
geom_text, geom_label
geom_rug
facet_wrap, facet_grid

Options

# Control size
ggplotcli(p, width = 80, height = 24)

# Canvas types
ggplotcli(p, canvas_type = "braille")  # High resolution (default)
ggplotcli(p, canvas_type = "block")    # Block characters
ggplotcli(p, canvas_type = "ascii")    # ASCII only

Direct R6 Class Usage

For lower-level control, use the plotcli R6 class directly:

pc <- plotcli$new(plot_width = 60, plot_height = 20, x_label = "wt", y_label = "mpg",
                  title = "MPG vs Weight")
pc$add_data(list(x = mtcars$wt, y = mtcars$mpg, type = "scatter", name = "mtcars"))
pc$print_plot()

Similar Projects

  • txtplot: The OG in R
  • r-plot: Collection of excellent terminal plotting functions
  • UnicodePlots.jl: The gold standard for terminal graphics
  • plotext: Powerful terminal graphics in Python

License

plotcli is released under the LGPL-3 License.

About

R package for terminal plots

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages