Day 1: §0d|0a|0t|1a|1l|1e|2g|2r|2e|2y|3a|3r|3

Welcome all to the first day of the #packagecalendar, today I’m going to start simple and awesome with the datalegreyar package by Emi Tanaka. The package provides an interface to the font datalagreya developed by Figs.

Since the package still is on GitHub you need to download it from there

# install.packages("devtools")

A datalegreyar composition requires two main parts. The text and the underlying data used to create the line. Where I’m living, Christmas music has been playing for quite a while, with “Last Christmas” being quite a popular choice. We can use the gtrendsR to retrieve the hit data from the last 3 months. Please note that the CRAN version of gtrendsR isn’t working well, download the developmental version from GitHub if you want to follow along.

# remotes::install_github("PMassicotte/gtrendsR")
last_christmas <- gtrends("Last Christmas", time = "today 3-m")

Then we load the datalegreyar package and use the datafy() function to combine the values and the text. Furthermore, we also specify that we would want to ignore the spaces so we have one continuous line.

last_christmas_data <- datafy(
  values = last_christmas$interest_over_time$hits,
  text = "Last Christmas",
  ignore_space = FALSE

## l a s t   c h r i s t m a s 
## 0 0 0 0 0 0 0 0 1 2 2 3 3 3 
## attr(,"class")
## [1] "datafied" "numeric"

Next, we pass the datafied object to fig() to render it in our document. I have manually set size to 60 as the default is quite small.

fig(last_christmas_data, size = 60)
§0l|0a|0s|0t|0 |0c|0h|0r|0i|1s|2t|2m|3a|3s|3

From here on we can add our final stylistic choice. There are simple self-explanatory arguments such as color and bgcolor(background color). One of the prominent is the type argument which specifies the area under the curve.

fig(last_christmas_data, size = 60, type = "thin")
§0l|0a|0s|0t|0 |0c|0h|0r|0i|1s|2t|2m|3a|3s|3
fig(last_christmas_data, size = 60, type = "gradient")
§0l|0a|0s|0t|0 |0c|0h|0r|0i|1s|2t|2m|3a|3s|3
fig(last_christmas_data, size = 60, type = "dot")
§0l|0a|0s|0t|0 |0c|0h|0r|0i|1s|2t|2m|3a|3s|3

I like the gradient type so I’ll stick with that one for now. Last we will use the xlabs argument to add little text above the datalegreyar. I’ll use the opportunity to label the start and endpoints for dates.

fig(last_christmas_data, size = 60, type = "gradient", 
    xlabs = c("sep 1", "dec 1"))
{sep 1}§0l|0a|0s|0t|0 |0c|0h|0r|0i|1s|2t|2m|3a|3s|3{dec 1}

Santa’s little datalegreyar factory

I already decided on a style I like, so I’m going to wrap up everything into a function and pass in a bunch of Christmas Song titles.

datalegreyar_factory <- function(text, size) {
  data <- datafy(
    values = gtrends(text, time = "today 3-m")$interest_over_time$hits,
    text = text,
    ignore_space = FALSE
  fig(data, size = size, type = "gradient", xlabs = c("sep 1", "dec 1"))

Then we just apply it many times and see the magic! This is all for today, keep an eye out for the next opening tomorrow!

datalegreyar_factory("Drummer Boy", size = 60) 
{sep 1}§0d|0r|0u|0m|0m|0e|0r|0 |1b|1o|2y|3{dec 1}
datalegreyar_factory("White Christmas", size = 50) 
{sep 1}§0w|0h|0i|0t|0e|0 |0c|0h|0r|1i|1s|1t|2m|2a|3s|3{dec 1}
datalegreyar_factory("We Wish You A Mary Christmas", size = 30) 
{sep 1}§0w|0e|0 |0w|0i|0s|0h|0 |0y|0o|0u|0 |0a|0 |0m|0a|0r|0y|0 |0c|0h|1r|1i|1s|2t|2m|2a|3s|3{dec 1}