The exhibitionist
package provides functions for showing and
annotating sequences of characters or numbers.
show_bit()
for showing bit sequences of integers and doubles in
the consoleplot_char()
for plotting a sequence of characters as defined in a
chars_df
data.frame with an annotation_df
data.frame used to
control the annotation underneat the characters.You can install from GitHub with:
# install.packages("devtools")
devtools::install_github("coolbutuseless/exhibitionist")
show_bit()
for displaying integers and doubles in the terminalshow_bits(12345.67)
#> 0 10000001100 (13) 1000000111001101010111000010100011110101110000101001 : 12345.67
show_bits(12345L)
#> 00000000000000000011000000111001
plot_double(1.2345e87)
plot_compact_double(1.2345e87, base_size = 5, legend.text.multiplier = 2)
The header of this page was made with this package.
The two key data.frames are:
chars_df
which must include the columnsx
for the the x-coordinate of the characterchar
for the character itselfannotation_df
which must include the columnsstart
/end
for the start and end of a line segment underneath
the tilessegment
/text
logical values which indicate whether the
segment and text should be drawnStyling columns:
text_
are passed to geom_text()
segment_
are passed to geom_segment()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create the characters data.frame
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chars_df <- tibble(
char = strsplit("Exhibitionist", '')[[1]],
x = seq_along(char),
text_colour = 'black'
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Set the word 'bit' to be BLUE text
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chars_df$text_colour[5:7] <- 'blue'
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# How should the individual characters be labelled
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
annotation_df <- readr::read_csv(
"start, end, segment, text, text_size, label , segment_colour, segment_size
1, 4, TRUE , TRUE, 7, A package for , grey30 , 1
5, 7, TRUE , TRUE, 7, annotating , darkgreen , 2
8, 13, TRUE , TRUE, 7, bit & char sequences, orange , 1
")
plot_chars(chars_df, annotation_df) + ylim(-2, 1.5)
This is a demonstration of a lot more options you can change to modify appearance.
In general:
text_
are passed to geom_text()
segment_
are passed to geom_segment()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create the characters data.frame
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chars_df <- tibble(
char = strsplit("Over the top", '')[[1]],
x = seq_along(char),
text_colour = 'black',
text_size = 11,
text_angle = 0
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Style a lot of the characters
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chars_df <- chars_df %>%
mutate(
text_colour = if_else(x %% 2 == 0, 'red', text_colour),
text_angle = if_else(x %% 3 == 0, 45 , text_angle ),
text_size = if_else(x %% 6 == 0, 28 , text_size ),
tile_fill = if_else(char == ' ', NA_character_, 'white'),
tile_colour = if_else(char == ' ', NA_character_, 'black')
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# How should the individual characters be labelled underneath?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
annotation_df <- readr::read_csv(
"start, end, segment, text, text_size, label , segment_colour, segment_linetype, segment_size, text_family, text_angle, text_hjust
1, 4, TRUE , TRUE, 10, Over it!! , darkgreen , 1 , 1 , serif , 0 , 0.5
6, 8, TRUE , TRUE, 7, Too Much? , blue , 2 , 2 , , 45 , 1
10, 12, TRUE , TRUE, 7, Or not enough?? , orange , 3 , 4 , , 180 , 0.5
")
plot_chars(chars_df, annotation_df) +
ylim(-2, 1.2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.