Introduction to ggplotcli

Claas Heuer

2025-11-27

Introduction

The ggplotcli() function converts any ggplot2 plot to a terminal-based visualization using Unicode Braille characters and ANSI colors.

Basic Usage

library(plotcli)
library(ggplot2)

# Create a ggplot with points and smooth line
mtcars_ggplot <- ggplot(mtcars, aes(x = mpg, y = wt)) +  
  geom_point() +  
  geom_smooth(method = "lm", color = "red") +
  labs(title = "Mtcars Dataset with Regression Line",  
       x = "Miles per Gallon",  
       y = "Weight")  

# Render in terminal
suppressMessages(ggplotcli(mtcars_ggplot, width = 60, height = 15))
#> 
#>            Mtcars Dataset with Regression Line               
#>          ⢠        ⡀                                          
#>    5.0                                                       
#> W        ⠐⠢⢄⣀⡀                                               
#> e  4.0       ⠈⠉⡑⠒⠤⠤⣀ ⠐     ⡀                                 
#> i                ⠄⠠⡡⠉⠉⠒⠣⣤⢄⣀⡀                                 
#> g  3.0              ⠂      ⠉⠉⠒⠤⠴⣀⡀⠂  ⠂                       
#> h                           ⠁ ⠨⢈ ⠈⠉⠑⠒⠤⢄⣀                     
#> t  2.0                            ⠁     ⠩⠉⠒⠢⠤⢄⡀      ⠂       
#>                                            ⠁  ⠈⠉⠑⡖⠤⠤⣀⣀  ⠁    
#>    1.0                                                ⠉⠑⠂    
#>                                                              
#>        10.0     15.0      20.0      25.0      30.0      35.0 
#>                         Miles per Gallon                     
#> 

Color Aesthetics

ggplotcli supports color grouping just like ggplot2:

# Colored by group
p <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
  geom_point() +
  labs(title = "MPG vs Weight by Cylinders",
       color = "Cylinders")

ggplotcli(p, width = 60, height = 14)
#> 
#>                 MPG vs Weight by Cylinders                       
#>   35.0       ⠄                                                   
#>          ⢀⢀      ⠈                                               
#>   30.0                                                      Cyl  
#> m             ⠈  ⠄                                          * 4  
#> p 25.0             ⡀         ⡈                              * 6  
#> g 20.0              ⠈ ⠐ ⢐⠐   ⠐                              * 8  
#>                                 ⠸   ⡀⠈                           
#>   15.0                       ⠂  ⠠⠠⡄ ⠠   ⠁              ⡀         
#>                                      ⠂                           
#>   10.0                                                ⠂ ⠂        
#>               2.0         3.0         4.0         5.0            
#>                                wt                                
#> 
# Iris dataset with species colors
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 = 12)
#> 
#>             Iris: Sepal Dimensions by Species                             
#> S  4.5                     ⠐                                              
#> e  4.0               ⠂ ⢀ ⠁   ⠄                              Species       
#> p            ⡀   ⡀⢀⠨  ⠠⠠   ⠈                   ⡀     ⠈  ⠁   * setosa      
#> a  3.5    ⢀  ⡂⢀ ⠂ ⢸⠸ ⠃ ⠐ ⠁    ⡀⠐  ⠂⠰⢀ ⡀ ⠠ ⡀⡀⢀  ⡀            * versicolor  
#> l  3.0   ⠠⢠  ⠂  ⠆⠆⠠    ⠠  ⡄⢠  ⠄⢠⢠ ⡀⢀⢐ ⠄⢠⠰ ⠄⠂  ⠄⠄⢀   ⠠⠠      * virginica   
#> .  2.5               ⠂   ⡀⠃⢈ ⡃ ⠐⢈ ⠁⠘⠘ ⠁   ⠁      ⠈   ⢈                    
#> W           ⠄    ⠃⠠⠈     ⠇⠁⠈   ⢀  ⡀⠨    ⠈                                 
#> i  2.0            ⠠                                                       
#>                  5.0          6.0          7.0          8.0               
#>                           Sepal.Length                                    
#> 

Density Plots with Colors

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            ⣠⢦                                             
#> e 0.20           ⢠⠃⠈⣇      ⢀⡠⠞⠙⣆                            fac  
#> n                ⡞  ⠸⡀  ⢠⠚⠉⠁   ⠸⡄                           * 4  
#> s 0.15          ⢠⠃   ⢣ ⢠⠃       ⢧                           * 6  
#> i 0.10         ⢀⡎    ⠈⢆⡎        ⠘⡄                          * 8  
#> t 0.05   ⠘⢦   ⢀⡞      ⡼⠳⠤⠖⠒⢦ ⢀⣠⠤⠖⢳⠒⠒⠒⠒⠒⠦⠤⠤⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀            
#> y         ⠈⢣⡀⣠⠞      ⡰⠁ ⢀⣀⡤⠔⢻⡉   ⠈⢧                 ⠈⠉⠉⠓⠂        
#>      0   ⠠⠤⠤⠭⠥⠤⠤⠤⠴⠶⠒⠚⠓⠒⠉⠉    ⠙⠒⠦⠤⠤⠬⠷⠶⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠄        
#>        10.0     15.0      20.0      25.0      30.0      35.0     
#>                               mpg                                
#> 

Faceting

facet_wrap

Split plots by a categorical variable:

p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(color = "blue") +
  facet_wrap(~cyl) +
  labs(title = "MPG vs Weight by Cylinders")

ggplotcli(p, width = 70, height = 14)
#> 
#>                      MPG vs Weight by Cylinders                        
#>                4                    6                    8             
#>         ⠠                                                              
#>        ⠤  ⠁                                                            
#>   30.0   ⡀                                                             
#>          ⠈    ⠠                                                        
#>           ⠐⠄⢀ ⠐                  ⡀⡀⢀                                   
#>   20.0                           ⠐  ⢐                    ⠠ ⠐           
#>                                                         ⠠⢀⡀⡁⠐          
#>                                                           ⠁⠐      ⠈    
#>   10.0                                                            ⠒    
#>         2.0      4.0         2.0      4.0         2.0      4.0         
#>                                                                        
#> 

facet_grid

Create a grid of plots by two variables:

p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(color = "green") +
  facet_grid(am ~ cyl) +
  labs(title = "MPG: Transmission (rows) x Cylinders (cols)")

ggplotcli(p, width = 70, height = 18)
#> 
#>             MPG: Transmission (rows) x Cylinders (cols)                
#>               0, 4                 0, 6                 0, 8           
#>                                                                        
#>   30.0                                                                 
#>               ⢐                                                        
#>   20.0     ⠁                       ⠈⢠                    ⢀ ⠠           
#>                                                          ⠠⠆⢅⠐     ⠠    
#>   10.0                                                            ⠤    
#>               1, 4                 1, 6                 1, 8           
#>         ⠐ ⠄                                                            
#>   30.0 ⠉ ⡀                                                             
#>          ⠈⢀                                                            
#>   20.0      ⠈                    ⠢⠂                                    
#>                                                         ⠐ ⠄            
#>   10.0                                                                 
#>         2.0      4.0         2.0      4.0         2.0      4.0         
#>                                                                        
#> 

Combining Multiple Geoms

# 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                 ⢰⣶⣶⣶⣶⣶                                     
#> e 0.08            ⢸⣿⣿⣿⣿⣿⣶⣶⣶⣶⣶⣶⣶⣶⣶                            
#> n 0.06            ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿                            
#> s               ⢀⡴⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠓⢦⡀                         
#> i 0.04        ⣀⠴⠋ ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣤⣤⣭⣶⣤⡀        ⣤⣤⣤⣤⣤         
#> t 0.02   ⢠⣤⣤⣤⣾⣥⣤⣤⣤⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣭⣶⣦⣤⣄⣀⣀⣀⣀⣿⣿⣿⣿⣿         
#> y        ⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇    ⣿⣿⣿⣿⣿⣽⣶⣤⣤⡄    
#>      0   ⠸⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠿⠧⠤⠤⠤⠤⠿⠿⠿⠿⠿⠿⠿⠿⠿⠇    
#>          10.0     15.0     20.0    25.0     30.0     35.0    
#>                               mpg                            
#> 

Canvas Types

Three rendering modes are available:

p <- ggplot(mtcars, aes(x = wt, y = mpg)) + 
  geom_point(color = "blue")

# High resolution with Braille (default)
ggplotcli(p + labs(title = "Braille Canvas (default)"), 
          width = 50, height = 10, canvas_type = "braille")
#> 
#>             Braille Canvas (default)               
#>   35.0      ⠂  ⠠                                   
#> m 30.0   ⠁⠁  ⡀                                     
#> p 25.0         ⠁⢀       ⢀⠂                         
#> g 20.0            ⠁⠐ ⠅⠂  ⠈ ⢠   ⠠                   
#>   15.0                   ⠂ ⠠⠢ ⠈⢄ ⠐            ⠄    
#>   10.0                                       ⠄⠠    
#>              2.0      3.0       4.0      5.0       
#>                           wt                       
#> 

# Block characters (medium resolution)
ggplotcli(p + labs(title = "Block Canvas"), 
          width = 50, height = 10, canvas_type = "block")
#> 
#>                   Block Canvas                     
#>   35.0      ▀  ▄                                   
#> m 30.0   ▀▀  ▄                                     
#> p 25.0         ▀ ▄      ▄▄                         
#> g 20.0            ▀▀ █▀  ▀ ▄   ▄                   
#>   15.0                   ▀ ▀█ ▀▄ ▀           ▄     
#>   10.0                                      ▄ ▄    
#>              2.0      3.0       4.0      5.0       
#>                           wt                       
#> 

# ASCII for maximum compatibility
ggplotcli(p + labs(title = "ASCII Canvas"), 
          width = 50, height = 10, canvas_type = "ascii")
#> 
#>                   ASCII Canvas                     
#>   35.0      *                                      
#> m 30.0   **    *                                   
#> p 25.0       * * *      **                         
#> g 20.0            ** **  * *  **                   
#>   15.0                   * ** ** *           *     
#>   10.0                                      * *    
#>              2.0      3.0       4.0      5.0       
#>                           wt                       
#> 

Styling Options

p <- ggplot(mtcars, aes(x = hp, y = qsec)) +
  geom_point(color = "cyan") +
  labs(title = "With Border and Grid")

# Add border and grid
ggplotcli(p, width = 55, height = 10, border = TRUE, grid = "major")
#> 
#>                 With Border and Grid                    
#>        ⡏⠉⢹⠉⠉⠉⠉⠉⠉⡉⡏⠉⠉⠉⠉⠉⠉⡏⠉⠉⠉⠉⠉⠉⡏⠉⠉⠉⠉⠉⠉⢹⠉⠉⠉⠉⠉⠉⢹⠉⠉⠉⠉⠉⠉⠉⢹  
#> q 22.0 ⡗⠒⢺⠒⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⠒⢺  
#> s 20.0 ⡗⠒⢺⠒⠒⡖⠒⠒⠒⠒⡟⠲⠒⡒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⡗⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⠒⢺  
#> e 18.0 ⡗⠒⢺⠓⠒⠒⠒⠒⠒⠓⡗⢓⠒⠓⠒⠒⠒⡗⠒⠒⢒⠲⠒⠒⡗⠒⠒⠒⠲⠒⠒⢺⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⠒⢺  
#> c 16.0 ⡗⠒⢺⠒⠒⠒⠒⠒⠚⠒⡗⠚⠒⠒⠒⠒⠒⡗⠒⠒⠲⠒⠒⠒⡗⠒⠒⠒⠒⠒⠲⢺⠒⠒⠒⠒⠒⠒⢺⠒⠒⠒⠒⠒⠒⠒⢺  
#>        ⣇⣀⣸⣀⣀⣀⣀⣀⣀⣀⣇⣀⣀⣀⣀⣀⣀⣇⣀⣀⣀⣀⣀⣀⣇⣀⣀⣀⣀⣀⣀⣸⣀⣈⣀⣀⣀⣀⣸⣀⣀⣀⣀⣈⣀⣀⣸  
#>        50.0    100     150    200    250     300        
#>                             hp                          
#> 

Theme Auto-Detection

ggplotcli automatically respects ggplot2 themes:

p <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point(color = "magenta")

# theme_bw adds grid and border
ggplotcli(p + theme_bw() + labs(title = "theme_bw() - Grid + Border"), 
          width = 55, height = 10, border = "auto", grid = "auto")
#> 
#>              theme_bw() - Grid + Border                 
#>   35.0 ⣏⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣹⣉⣉⣉⣉⣹⣉⣉⣉⣉⣹⣉⣉⣉⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣹⣉⣹  
#> m 30.0 ⣯⣭⣭⣯⣯⣭⣭⣭⣯⣭⣭⣭⣭⣯⣭⣭⣭⣭⣽⣭⣭⣭⣭⣽⣭⣭⣭⣭⣽⣭⣭⣭⣭⣭⣯⣭⣭⣭⣭⣯⣭⣭⣭⣭⣽⣭⣽  
#> p 25.0 ⡷⠶⠶⡷⠶⠶⠶⠾⡷⠶⠶⢶⠶⡷⠶⠶⠶⠶⢾⠶⡶⠶⠶⢾⠶⠶⠶⠶⢾⠶⠶⠶⠶⠶⡷⠶⠶⠶⠶⡷⠶⠶⠶⠶⢾⠶⢾  
#> g 20.0 ⣟⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣻⣛⣛⣛⣛⣿⣛⣛⣛⣟⣻⣛⣛⣛⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣻⣛⣻  
#>   15.0 ⣟⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣻⣛⣛⣛⣛⣻⣛⣛⣛⣟⣻⣛⣛⣛⣛⣛⣟⣛⣛⣛⣛⣟⣛⣛⣛⣛⣻⣛⣻  
#>   10.0 ⣏⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣹⣉⣉⣉⣉⣹⣉⣉⣉⣉⣹⣉⣉⣉⣉⣉⣏⣉⣉⣉⣉⣏⣉⣉⣉⣉⣹⣉⣹  
#>              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 = 55, height = 10, border = "auto", grid = "auto")
#> 
#>             theme_classic() - Border Only               
#>   35.0 ⡏⠉⠉⠉⠉⠉⢉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⢹  
#> m 30.0 ⡇  ⠂⠂     ⠁                                   ⢸  
#> p 25.0 ⡇      ⠈ ⠐ ⢀        ⡠                         ⢸  
#> g 20.0 ⡇            ⠁⠈ ⠃⠁  ⠈  ⡄  ⡀⠄                  ⢸  
#>   15.0 ⡇                   ⠁  ⠂⠑ ⠐⠄ ⠈            ⠐   ⢸  
#>   10.0 ⣇⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣈⣀⣈⣀⣀⣸  
#>              2.0        3.0        4.0       5.0        
#>                             wt                          
#> 

Learn More

See the full vignette “ggplotcli: Universal ggplot2 to Terminal Plotting” for more examples including all supported geoms, advanced styling, and more.