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")
devtools::install_github('emitanaka/datalegreyar')

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")
library(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.

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

last_christmas_data
## l a s t   c h r i s t m a s 
## 3 3 3 2 2 1 0 0 0 0 0 0 0 0 
## 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|3a|3s|3t|2 |2c|1h|0r|0i|0s|0t|0m|0a|0s|0

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|3a|3s|3t|2 |2c|1h|0r|0i|0s|0t|0m|0a|0s|0
fig(last_christmas_data, size = 60, type = "gradient")
§0l|3a|3s|3t|2 |2c|1h|0r|0i|0s|0t|0m|0a|0s|0
fig(last_christmas_data, size = 60, type = "dot")
§0l|3a|3s|3t|2 |2c|1h|0r|0i|0s|0t|0m|0a|0s|0

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|3a|3s|3t|2 |2c|1h|0r|0i|0s|0t|0m|0a|0s|0{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|3r|3u|3m|2m|1e|0r|0 |0b|0o|0y|0{dec 1}
datalegreyar_factory("White Christmas", size = 50) 
{sep 1}§0w|3h|3i|3t|2e|2 |1c|1h|0r|0i|0s|0t|0m|0a|0s|0{dec 1}
datalegreyar_factory("We Wish You A Mary Christmas", size = 30) 
{sep 1}§0w|3e|3 |3w|3i|3s|3h|2 |2y|2o|2u|1 |1a|0 |0m|0a|0r|0y|0 |0c|0h|0r|0i|0s|0t|0m|0a|0s|0{dec 1}