plot_text
parses text
(from a file or from user input in Console)
into a table and then plots all
its characters as a tile plot (using ggplot2).
plot_text(
file = "",
char_bg = " ",
lbl_tiles = TRUE,
lbl_rotate = FALSE,
cex = 3,
fontface = 1,
family = "sans",
col_lbl = "black",
col_bg = "white",
pal = pal_ds4psy[1:5],
pal_extend = TRUE,
case_sense = FALSE,
borders = TRUE,
border_col = "white",
border_size = 0.5
)
The text file to read (or its path).
If file = ""
(the default), scan
is used
to read user input from the Console.
If a text file is stored in a sub-directory,
enter its path and name here (without any leading or
trailing "." or "/").
Default: file = ""
.
Character used as background.
Default: char_bg = " "
.
If char_bg = NA
, the most frequent character is used.
Add character labels to tiles?
Default: lbl_tiles = TRUE
(i.e., show labels).
Rotate character labels?
Default: lbl_rotate = FALSE
(i.e., no rotation).
Character size (numeric).
Default: cex = 3
.
Font face of text labels (numeric).
Default: fontface = 1
, (from 1 to 4).
Font family of text labels (name).
Default: family = "sans"
.
Alternative options: "sans", "serif", or "mono".
Color of text labels.
Default: col_lbl = "black"
(if lbl_tiles = TRUE
).
Color of char_bg
(if defined),
or the most frequent character in text (typically " "
).
Default: col_bg = "white"
.
Color palette for filling tiles
of text (used in order of character frequency).
Default: pal = pal_ds4psy[1:5]
(i.e., shades of Seeblau
).
Boolean: Should pal be extended
to match the number of different characters in text?
Default: pal_extend = TRUE
.
If pal_extend = FALSE
, only the tiles of
the length(pal)
most frequent characters
will be filled by the colors of pal
.
Boolean: Should lower- and
uppercase characters be distinguished?
Default: case_sense = FALSE
.
Boolean: Add borders to tiles?
Default: borders = TRUE
(i.e., use borders).
Color of borders (if borders = TRUE
).
Default: border_col = "white"
.
Size of borders (if borders = TRUE
).
Default: border_size = 0.5
.
read_ascii
for reading text into a table;
pal_ds4psy
for default color palette.
Other plot functions:
plot_fn()
,
plot_fun()
,
plot_n()
,
plot_tiles()
,
theme_clean()
,
theme_ds4psy()
,
theme_empty()
# NOT RUN {
## Create a temporary file "test.txt":
# cat("Hello world!", "This is a test.",
# "Can you see this text?",
# "Good! Please carry on...",
# file = "test.txt", sep = "\n")
## (a) Plot text (from file):
# plot_text("test.txt")
## Set colors, pal_extend, and case_sense:
# cols <- c("steelblue", "skyblue", "lightgrey")
# cols <- c("firebrick", "olivedrab", "steelblue", "orange", "gold")
# plot_text("test.txt", pal = cols, pal_extend = TRUE)
# plot_text("test.txt", pal = cols, pal_extend = FALSE)
# plot_text("test.txt", pal = cols, pal_extend = FALSE, case_sense = TRUE)
## Customize text and grid options:
# plot_text("test.txt", col_lbl = "darkblue", cex = 4, family = "sans", fontface = 3,
# pal = "gold1", pal_extend = TRUE, border_col = NA)
# plot_text("test.txt", family = "serif", cex = 6, lbl_rotate = TRUE,
# pal = NA, borders = FALSE)
# plot_text("test.txt", col_lbl = "white", pal = c("green3", "black"),
# border_col = "black", border_size = .2)
## Color ranges:
# plot_text("test.txt", pal = c("red2", "orange", "gold"))
# plot_text("test.txt", pal = c("olivedrab4", "gold"))
# unlink("test.txt") # clean up (by deleting file).
# }
# NOT RUN {
## (b) Plot text (from file in subdir):
# plot_text("data-raw/txt/hello.txt") # requires txt file
# plot_text(file = "data-raw/txt/ascii.txt", cex = 5,
# col_bg = "grey", char_bg = "-")
## (c) Plot text input (from console):
# plot_text()
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab