Character mode redraws a ggplot on a grid of monospaced characters,
the way home computers of the 1980s drew charts on a text screen. The
grid prints as text in the console, and char_figure() turns
it back into a ggplot of glyphs that can be saved as a figure, in black
and white, in the colours of a Commodore 64 screen or as that screen in
two values.
char_grid() takes a single-panel Cartesian ggplot,
builds it and draws its layers into a character matrix. The output is
deterministic: the same plot and arguments always give the same
grid.
chicks <- aggregate(weight ~ Time, data = ChickWeight, FUN = mean)
p <- ggplot(chicks, aes(Time, weight)) +
geom_line() +
geom_point() +
labs(title = "Chick weight", x = "Days since birth", y = "Mean weight (g)")
char_grid(p, width = 56, height = 16)Chick weight
Mean weight (g)
| *
200 + --*/
| /*--
| /*//
150 + /*//
| --*//
100 + /*---*--
| /*//
50 + /*----*//
| *//
+--+----------+---------+----------+----------+----
0 5 10 15 20
Days since birth
From the top, the grid holds the title, the y-axis label, the plot
rows, the x axis with a + at every break, the tick labels,
the x-axis label, the legend and the caption. The first series draws
lines with slope glyphs chosen for cells twice as tall as wide.
Supported layers are rectangles (bars, columns, tiles), ribbons and
areas, smooths (the line only), paths and lines, segments, error bars
and ranges, reference lines, points and text. Other layers, such as box
plots and violins, are skipped with one warning of class
infereportR_skipped_layer. Facets and flipped, polar or
transformed coordinates are errors of class
infereportR_unsupported.
Series are told apart by glyph, never by colour. The key comes from
the first discrete scale among fill, colour,
shape and linetype with at least two breaks,
and the legend under the grid shows each series’ glyph:
diets <- aggregate(weight ~ Diet + Time, data = ChickWeight, FUN = mean,
subset = Diet %in% c("1", "4"))
q <- ggplot(diets, aes(Time, weight, linetype = Diet)) +
geom_line() +
labs(x = "Days since birth", y = "Mean weight (g)", linetype = "Diet")
char_grid(q, width = 56, height = 14)Mean weight (g)
| .
| ....
200 + ........
| .... /--------
150 + ..... ////
100 + ........------///
| ..../-------
50 + .........-///
| ...
+--+----------+---------+----------+----------+----
0 5 10 15 20
Days since birth
/ 1 . 4
A geom_endlabel() layer is not drawn inside the grid.
Each series gets an end label right of the plot area instead, written as
its point glyph and its label and ordered by the series’ last value,
highest on top. Two labels never share a row: the lower one moves down.
The plot area gives up the columns the labels need, and the legend is
left out, since the end labels name the same series.
labeled <- transform(diets, Diet = paste("Diet", Diet))
e <- ggplot(labeled, aes(Time, weight, shape = Diet, label = Diet)) +
geom_line(aes(group = Diet)) +
geom_point() +
geom_endlabel() +
labs(x = "Days since birth", y = "Mean weight (g)")
char_grid(e, width = 56, height = 14)Mean weight (g)
| o o Diet 4
| .o.
200 + .o.
| .o. /*-* * Diet 1
150 + .o..o../*--*/
| .o.. /*//
100 + .o./*---*/
| .o../*/
50 + .o...o.-*//
| o.
+--+-------+--------+--------+-------+----
0 5 10 15 20
Days since birth
charset = "unicode" uses box-drawing glyphs for lines,
geometric shapes for points and block glyphs for fills;
"ascii" (the default) stays within printable ASCII.
case = "upper" writes every string in upper case, as on
machines without lower-case letters; the glyphs of the data do not
change. With "ascii", every string is transliterated to
ASCII as well: ≥ becomes >=, ≤
<=, ± +/-, ×
x, the minus sign and the en dash -, the em
dash --, µ u and ρ
rho. Any other non-ASCII character becomes ?,
with one warning of class infereportR_transliterated.
tooth <- aggregate(len ~ dose, data = ToothGrowth, FUN = mean)
bars <- ggplot(tooth, aes(factor(dose), len)) +
geom_col(width = 0.5) +
labs(x = "Dose (mg/day)", y = "Mean tooth length (mm)")
char_grid(bars, width = 40, height = 12, charset = "unicode", case = "upper")MEAN TOOTH LENGTH (MM)
| ██████
| ██████
20 + ███████ ██████
| ███████ ██████
10 + ██████ ███████ ██████
| ██████ ███████ ██████
| ██████ ███████ ██████
0 + ██████ ███████ ██████
+------+----------+----------+------
0.5 1 2
DOSE (MG/DAY)
A grid prints with print(); format() and
as.character() return its lines, and the object also holds
the character matrix (chars) and the legend table.
char_figure() draws a grid as a ggplot made only of
text, one glyph per non-blank cell. The "bw" style is black
on white without a margin, the 1-bit style of the package, with a 64 x
20 grid by default.
The "c64" style imitates the screen of a Commodore 64
after power-on: light blue glyphs on a blue screen inside a light blue
border, a 40 x 25 grid, labels in upper case and, by default,
READY. with a cursor below the chart. The cursor is a
filled tile rather than a block glyph, which IBM Plex Mono lacks. The
two colours are the VIC-II “blue” (#352879) and “light
blue” (#6C5EB5) of the Pepto palette by Philip Timmermann.
They are the only colours in the package.
The c64 style is for effect only: it is not black and white, and
check_figure() reports it under two_values.
The "c64bw" style keeps the look in two values. The screen
is always black with white glyphs, and the border stands in for the
lighter border blue with a dot halftone, ink dots on paper 0.75 mm
apart. In dark mode only the border changes, to white dots on black.
Glyphs only line up if the figure is saved at the size of the grid.
char_size() computes it: the figure is
width_mm wide (134 mm, the Bleisatz text width, by
default), border included. Each cell is
(width_mm - 2 * border) / (ncol + 2 * padding columns) wide
and cell_ratio (1.75) times as tall. The c64 border takes
6% of width_mm on every side and has no padding; the
c64bw border is 3.2 mm, with one column of padding left and
right and 0.4 rows above and below.
char_size(p)
#> $width
#> [1] 134
#>
#> $height
#> [1] 73.28125
#>
#> $units
#> [1] "mm"
char_size(p, style = "c64")
#> $width
#> [1] 134
#>
#> $height
#> [1] 155.373
#>
#> $units
#> [1] "mm"
char_size(p, width_mm = 86)
#> $width
#> [1] 86
#>
#> $height
#> [1] 47.03125
#>
#> $units
#> [1] "mm"Pass the size to save_figure(), and the same
width_mm, cell_ratio and style to
char_figure() and char_size():
fig <- char_figure(p, width_mm = 86)
size <- char_size(fig, width_mm = 86)
out <- save_figure(fig, file.path(tempdir(), "chicks-char.png"),
width = size$width, height = size$height, dpi = 300)
file.exists(out)
#> [1] TRUEWith slot, a size preset of figure_size(),
the figure takes the slot’s width and height. The number of rows is then
the largest that fits the slot height, READY. included, and
what is left over (less than a row) is split above and below the grid.
In a slot, the c64 styles default to 38 columns, which suits
"slide_half". Here is the "c64bw" style in a
half-width slot, in light and dark mode:
char_figure(p, style = "c64bw", slot = "slide_half")
char_figure(p, style = "c64bw", slot = "slide_half", mode = "dark")char_size(p, style = "c64bw", slot = "slide_half")
#> $width
#> [1] 64
#>
#> $height
#> [1] 44
#>
#> $units
#> [1] "mm"With transparent = TRUE every style draws glyphs only,
without screen, border or background, at the same size, so the
transparent file can replace the opaque one on a frame with a background
of its own.
The text size is chosen so that one glyph advance fills one cell:
(width_mm / ncol) / char_width mm, where
char_width is the advance width of the font in em. The
default 0.6 fits IBM Plex Mono and DejaVu Sans Mono.
The figures above use figure_font("mono"): IBM Plex Mono
when it is installed, otherwise R’s generic "mono" family.
For the look of the real machine, install the C64 Pro Mono font by
Style64. Its licence does not allow it to be bundled, so it is not part
of this package. Make it known to the graphics device (for example
through systemfonts for the ragg devices), then use square cells one em
wide:
The C64 colours are the Pepto palette of the VIC-II chip by Philip
Timmermann, as shipped with the VICE emulator in
pepto-pal.vpl. IBM Plex is released under the SIL Open Font
License (https://github.com/IBM/plex). See the README for the
full list of sources.
This package is part of an inference suite (infercalcR, inferguidR and infereportR) that is deeply inspired by DescrTab2 [1], developed at the Institute of Medical Biometry (IMBI), Heidelberg University, by Jan Meis, Lukas Baumann, Maximilian Pilz and Lukas Sauer. Its test-choice tree, its validation statement and its practice of computing each test with an established implementation are the model for how the suite chooses, computes and reports statistical tests. DescrTab2 was archived on CRAN on 18 October 2025; its source code remains available on GitHub. The methods-consulting pages of the University of Zurich [2], with their decision tree, decision assistant, worked examples and explanations, inspired the guidance in the suite. Power and sample-size planning and the distribution calculator follow G*Power 3.1 [3, 4]. We thank the authors of these works for making them openly available. The package README cites all software the package uses.