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")
#> No encoding supplied: defaulting to UTF-8.
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))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
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.
- The qrencoder package
generate to QR codes that form the basis for much of
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. - Without ggplot2 there would
be little point to a package like
ggtrack
. The entire banner object is aggplot
withtheme_void
andannotation_custom
used to place the three tracking elements. - The
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 theggplot
object on top of the tracking banner.- The stegasaur is used the
encode arbitrary text or R objects into the plot
PNG
. This is very cool and stegasaur is a great package that makes it really easy to encode and decode images.