plot_charmap | R Documentation |
plot_charmap
plots a character map and some aesthetics
as a tile plot with text labels (using ggplot2).
plot_charmap(
x = NA,
file = "",
lbl_tiles = TRUE,
col_lbl = "black",
angle = 0,
cex = 3,
fontface = 1,
family = "sans",
col_bg = "grey80",
borders = FALSE,
border_col = "white",
border_size = 0.5
)
x |
A character map, as generated by
|
file |
A text file to read (or its path).
If |
lbl_tiles |
Add character labels to tiles?
Default: |
col_lbl |
Default color of text labels
(unless specified as a column |
angle |
Default angle of text labels
(unless specified as a column of |
cex |
Character size (numeric).
Default: |
fontface |
Font face of text labels (numeric).
Default: |
family |
Font family of text labels (name).
Default: |
col_bg |
Default color to fill background tiles
(unless specified as a column |
borders |
Boolean: Add borders to tiles?
Default: |
border_col |
Color of tile borders.
Default: |
border_size |
Size of tile borders.
Default: |
plot_charmap
is based on plot_chars
.
As it only contains the plotting-related parts,
it assumes a character map generated by
map_text_regex
as input.
The plot generated by plot_charmap
is character-based:
Individual characters are plotted at equidistant x-y-positions
and aesthetic variables are used for text labels and tile fill colors.
A plot generated by ggplot2.
plot_chars
for creating and plotting character maps;
plot_text
for plotting characters and color tiles by frequency;
map_text_regex
for mapping text to a character table and matching patterns;
map_text_coord
for mapping text to a table of character coordinates;
read_ascii
for reading text inputs into a character string;
pal_ds4psy
for default color palette.
Other plot functions:
plot_chars()
,
plot_fn()
,
plot_fun()
,
plot_n()
,
plot_text()
,
plot_tiles()
,
theme_clean()
,
theme_ds4psy()
,
theme_empty()
# (0) Prepare:
ts <- c("Hello world!", "This is a test to test this splendid function",
"Does this work?", "That's good.", "Please carry on.")
sum(nchar(ts))
# (1) From character map:
# (a) simple:
cm_1 <- map_text_coord(x = ts, flip_y = TRUE)
plot_charmap(cm_1)
# (b) pattern matching (regex):
cm_2 <- map_text_regex(ts, lbl_hi = "\\b\\w{4}\\b", bg_hi = "[good|test]",
lbl_rotate = "[^aeiou]", angle_fg = c(-45, +45))
plot_charmap(cm_2)
# (2) Alternative inputs:
# (a) From text string(s):
plot_charmap(ts)
# (b) From user input:
# plot_charmap() # (enter text in Console)
# (c) From 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_charmap(file = "test.txt")
# unlink("test.txt") # clean up (by deleting file).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.