knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", fig.width = 9, fig.height = 2 ) suppressPackageStartupMessages({ library(ggplot2) library(dplyr) library(exhibitionist) })
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)
show_bits(12345L)
plot_double(1.2345e87)
plot_compact_double(1.2345e87, base_size = 5, legend.text.multiplier = 2)
chars_df <- tibble( char = strsplit("867-5309", '')[[1]], x = seq_along(char) ) annotation_df <- tribble( ~start, ~end, ~text, ~segment, ~label, ~segment_colour, ~segment_size, 1, 3, TRUE, TRUE, "Jenny", 'darkgreen' , 2, 5, 8, TRUE, FALSE, "I got your number", 'grey60' , 2 ) plot_chars(chars_df, annotation_df) + ylim(-2, 1.5)
chars_df <- tibble( char = strsplit("3.1415926535", '')[[1]], x = seq_along(char) ) chars_df <- chars_df %>% mutate( tile_fill = if_else(x %in% 5:7, 'red', 'grey80') ) annotation_df <- tribble( ~start, ~end, ~text, ~segment, ~label, ~segment_colour, ~segment_size, ~text_size, ~text_y, 5, 7, TRUE, TRUE, "Height of Great Pyramid of Giza\n(yards)", 'darkgreen' , 2, 6, -1.1 ) plot_chars(chars_df, annotation_df) + ylim(-2, 1.5)
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)
ggsave(filename = "man/figures/header.png")
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.