plot_chars | R Documentation |
plot_chars
parses text (from a file or user input)
into a table and then plots its individual characters
as a tile plot (using ggplot2).
plot_chars(
x = NA,
file = "",
lbl_hi = NA,
lbl_lo = NA,
bg_hi = NA,
bg_lo = "[[:space:]]",
lbl_rotate = NA,
case_sense = TRUE,
lbl_tiles = TRUE,
angle_fg = c(-90, 90),
angle_bg = 0,
col_lbl = "black",
col_lbl_hi = pal_ds4psy[[1]],
col_lbl_lo = pal_ds4psy[[9]],
col_bg = pal_ds4psy[[7]],
col_bg_hi = pal_ds4psy[[4]],
col_bg_lo = "white",
col_sample = FALSE,
rseed = NA,
cex = 3,
fontface = 1,
family = "sans",
borders = FALSE,
border_col = "white",
border_size = 0.5
)
x |
The text to plot (as a character vector).
Different elements denote different lines of text.
If |
file |
A text file to read (or its path).
If |
lbl_hi |
Labels to highlight (as regex).
Default: |
lbl_lo |
Labels to de-emphasize (as regex).
Default: |
bg_hi |
Background tiles to highlight (as regex).
Default: |
bg_lo |
Background tiles to de-emphasize (as regex).
Default: |
lbl_rotate |
Labels to rotate (as regex).
Default: |
case_sense |
Boolean: Distinguish
lower- vs. uppercase characters in pattern matches?
Default: |
lbl_tiles |
Add character labels to tiles?
Default: |
angle_fg |
Angle(s) for rotating character labels
matching the pattern of the |
angle_bg |
Angle(s) of rotating character labels
not matching the pattern of the |
col_lbl |
Default color of text labels.
Default: |
col_lbl_hi |
Highlighting color of text labels.
Default: |
col_lbl_lo |
De-emphasizing color of text labels.
Default: |
col_bg |
Default color to fill background tiles.
Default: |
col_bg_hi |
Highlighting color to fill background tiles.
Default: |
col_bg_lo |
De-emphasizing color to fill background tiles.
Default: |
col_sample |
Boolean: Sample color vectors (within category)?
Default: |
rseed |
Random seed (number).
Default: |
cex |
Character size (numeric).
Default: |
fontface |
Font face of text labels (numeric).
Default: |
family |
Font family of text labels (name).
Default: |
borders |
Boolean: Add borders to tiles?
Default: |
border_col |
Color of tile borders.
Default: |
border_size |
Size of tile borders.
Default: |
plot_chars
blurs the boundary between a text
and its graphical representation by combining options
for matching patterns of text with visual features
for displaying characters (e.g., their color or orientation).
plot_chars
is based on plot_text
,
but provides additional support for detecting and displaying characters
(i.e., text labels, their orientation, and color options)
based on matching regular expression (regex).
Internally, plot_chars
is a wrapper that calls
(1) map_text_regex
for creating a character map
(allowing for matching patterns for some aesthetics) and
(2) plot_charmap
for plotting this character map.
However, in contrast to plot_charmap
,
plot_chars
invisibly returns a
description of the plot (as a data frame).
The plot generated by plot_chars
is character-based:
Individual characters are plotted at equidistant x-y-positions
and the aesthetic settings provided for text labels and tile fill colors.
Five regular expressions and corresponding color and angle arguments allow identifying, marking (highlighting or de-emphasizing), and rotating those sets of characters (i.e, their text labels or fill colors). that match the provided patterns.
An invisible data frame describing the plot.
plot_charmap
for plotting character maps;
plot_text
for plotting characters and color tiles by frequency;
map_text_coord
for mapping text to a table of character coordinates;
map_text_regex
for mapping text to a character table and matching patterns;
read_ascii
for reading text inputs into a character string;
pal_ds4psy
for default color palette.
Other plot functions:
plot_charmap()
,
plot_fn()
,
plot_fun()
,
plot_n()
,
plot_text()
,
plot_tiles()
,
theme_clean()
,
theme_ds4psy()
,
theme_empty()
# (A) From text string(s):
plot_chars(x = c("Hello world!", "Does this work?",
"That's good.", "Please carry on..."))
# (B) From user input:
# plot_chars() # (enter text in Console)
# (C) From text file:
# Create and use a text file:
# cat("Hello world!", "This is a test file.",
# "Can you see this text?",
# "Good! Please carry on...",
# file = "test.txt", sep = "\n")
# plot_chars(file = "test.txt") # default
# plot_chars(file = "test.txt", lbl_hi = "[[:upper:]]", lbl_lo = "[[:punct:]]",
# col_lbl_hi = "red", col_lbl_lo = "blue")
# plot_chars(file = "test.txt", lbl_hi = "[aeiou]", col_lbl_hi = "red",
# col_bg = "white", bg_hi = "see") # mark vowels and "see" (in bg)
# plot_chars(file = "test.txt", bg_hi = "[aeiou]", col_bg_hi = "gold") # mark (bg of) vowels
## Label options:
# plot_chars(file = "test.txt", bg_hi = "see", lbl_tiles = FALSE)
# plot_chars(file = "test.txt", cex = 5, family = "mono", fontface = 4, lbl_angle = c(-20, 20))
## Note: plot_chars() invisibly returns a description of the plot (as df):
# tb <- plot_chars(file = "test.txt", lbl_hi = "[aeiou]", lbl_rotate = TRUE)
# head(tb)
# unlink("test.txt") # clean up (by deleting file).
## (B) From text file (in subdir):
# plot_chars(file = "data-raw/txt/hello.txt") # requires txt file
# plot_chars(file = "data-raw/txt/ascii.txt", lbl_hi = "[2468]", bg_lo = "[[:digit:]]",
# col_lbl_hi = "red", cex = 10, fontface = 2)
## (C) User input:
# plot_chars() # (enter text in Console)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.