knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Sometimes in a workplace it is hard to know exactly where or when a specific chart has been produced. This is especially true when someone has copied a chart out of a report to use somewhere else. The ggtrack
package aims to solve this problem by embedding enough metadata in the charts image to identify the source and the exact time it was produced.
The metadata is added by way of a QR code embedded in a chart "tracking" footer. The QR code can encode any arbitrary text and will append a time stamp. The text is intended to be a URL or a unique id for the original document or chart source.
QR codes can then be scanned using a phone scanner or the quadrangle package.
The ggtrack
footer can also display a corporate logo and additional text.
You can install the latest version of project from Github with:
devtools::install_github("mrjoh3/ggtrack")
On a linux system you may also need to install the png and jpeg libs.
sudo apt install libpng-dev libjpeg-dev
This package is still quite young but now contains most of the desired features. It now has a full testing suite and documentation. For future updates all efforts will be made to maintain a stable API. If you have any suggestions, or feature requests please submit an issue. All feedback is welcome.
To start you just need a ggplot
and some text you wish to encode into the QR. The QR is intended to contain enough information to uniquely identify the report, so a URL, file name or other unique identifier. The QR encode process automatically appends a time stamp. But try to keep the content of the QR code minimal. The for information it is the more pixels its requires and the larger it needs to be. The examples here need a QR code size of 1.8cm to be reliably scanned using a phone off the screen. QR code are encoded using the qrencoder package.
library(ggtrack) library(ggplot2) library(grid) library(rWBclimate) library(ggthemes) temp <- get_historical_temp('aus', "year") tp <- ggplot(temp, aes(x = year, y = data)) + geom_path(color = 'blue') + geom_point(color = 'darkblue') + labs(title = 'Average Annual Temperature for Australia', y = 'degrees celcius') + stat_smooth(se = TRUE, colour = "darkred") + theme_fivethirtyeight() ggtrack(tp, qr_content = paste0('Data accessed using R package: ', 'https://github.com/ropensci/rWBclimate / ', 'https://docs.ropensci.org/rWBclimate/'), logo = 'man/figures/ggtrack-logo.svg', caption = paste0('data accessed from the World Bank <br>', 'Climate Portal via the R package <br>', '<span style="color:blue">rWBclimate</span>.'), plot.background = element_rect(fill = "#f0f0f0", size = 0))
The ggrack
package makes use of many R packages. But I want to include a special thank-you to some packages without which the ggtrack
package would not be possible.
ggtrack
. qrencoder
is both fast and easy to use, and provides a variety of outputs that make it easy to incorporate QR codes into a project.ggtrack
. The entire banner object is a ggplot
with theme_void
and annotation_custom
used to place the three tracking elements.rasterGrob
elements from the grid package make it possible to add both the QR code and arbitrary images such as logos.grid.arrange
from gridExtra makes it possible to stack the ggplot
object on top of the tracking banner.PNG
. This is very cool and stegasaur is a great package that makes it really easy to encode and decode images.Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.