Type: | Package |
Title: | Lightweight Sparklines for a LaTeX Document |
Version: | 1.1.3 |
Date: | 2022-04-05 |
Description: | Sparklines are small plots (about one line of text high), made popular by Edward Tufte. This package is the interface from R to the LaTeX package sparklines by Andreas Loeffer and Dan Luecking (http://www.ctan.org/pkg/sparklines). It can work with Sweave or knitr or other engines that produce TeX. The package can be used to plot vectors, matrices, data frames, time series (in ts or zoo format). |
Suggests: | zoo |
License: | GPL-2 | GPL-3 |
URL: | https://github.com/borisveytsman/ltxsparklines |
NeedsCompilation: | no |
Packaged: | 2022-04-06 02:07:29 UTC; boris |
Author: | Boris Veytsman [aut, cre] |
Maintainer: | Boris Veytsman <borisv@lk.net> |
Repository: | CRAN |
Date/Publication: | 2022-04-06 06:42:29 UTC |
Lightweight Sparklines for a LaTeX Document
Description
Sparklines are small plots (about one line of text high), made popular by Edward Tufte. This package is the interface from R to the LaTeX package sparklines by Andreas Loeffer and Dan Luecking (<http://www.ctan.org/pkg/sparklines>). It can work with Sweave or knitr or other engines that produce TeX. The package can be used to plot vectors, matrices, data frames, time series (in ts or zoo format).
Details
The DESCRIPTION file:
Package: | ltxsparklines |
Type: | Package |
Title: | Lightweight Sparklines for a LaTeX Document |
Version: | 1.1.3 |
Authors@R: | c(person("Boris", "Veytsman", role = c("aut", "cre"), email = "borisv@lk.net")) |
Date: | 2022-04-05 |
Description: | Sparklines are small plots (about one line of text high), made popular by Edward Tufte. This package is the interface from R to the LaTeX package sparklines by Andreas Loeffer and Dan Luecking (<http://www.ctan.org/pkg/sparklines>). It can work with Sweave or knitr or other engines that produce TeX. The package can be used to plot vectors, matrices, data frames, time series (in ts or zoo format). |
Suggests: | zoo |
License: | GPL-2 | GPL-3 |
URL: | https://github.com/borisveytsman/ltxsparklines |
Author: | Boris Veytsman [aut, cre] |
Maintainer: | Boris Veytsman <borisv@lk.net> |
Index of help topics:
ltxsparklines-package Lightweight Sparklines for a LaTeX Document sparkline Create a Sparkline
Further information is available in the following vignettes:
ltxsparklines | sparklines (source, pdf) |
There are several packages that produce sparklines in R: SparkTable by Alexander Kowarik, Bernhard Meindl, Matthias Templ (https://CRAN.R-project.org/package=sparkTable), sparklines by Bart (https://github.com/Bart6114/sparklines). However, they either provide HTML-only output, or require Java libraries. This is a lightweight and easy to use package for LaTeX users.
The package provides one function, sparkline
, which
outputs LaTeX code compatible with LaTeX package sparklines
(Andreas Loeffer and Dan Luecking, http://www.ctan.org/pkg/sparklines).
Package options and setup
Do not forget to add \usepackage{sparklines}
to the preamble
of your TeX document.
There are two sets of options for
sparklines in LaTeX: those which are set from TeX, and those which are
set from R. The TeX options should be set with \renewcommand
,
\definecolor
or \setlength
, for example,
% The height of the sparklines in ex units \renewcommand\sparklineheight{1.75} % The line width \setlength\sparklinethickness{0.4pt} % The color of the sparkline \definecolor{sparklinecolor}{named}{blue} % The color of the sparkine rectangle when present \definecolor{sparkrectanglecolor}{gray}{0.8} % The dot width \setlength\sparkdotwidth{2pt} % The color of the spikes \definecolor{sparkspikecolor}{named}{red} % The color of the bottom line when present \definecolor{bottomlinecolor}{gray}{0.2} % The thickness of the bottom line \setlength\sparkbottomlinethickness{.2pt} % The clipping separation (need sparklines v1.7 or later) \setlength\sparklineclipsep{2pt}
See the documentation for the LaTeX sparklines
package.
Most options set from R define the defaults for sparkline
command. They can
be overriden by the corresponding argument of sparkline
, for
example, sparkline(...,width=20)
.
- ltxsparklines.width
The width of the sparkline (
10
).- ltxsparklines.clip
Whether to clip the sparklines in the drawing region (
FALSE
). You need LaTeXsparklines
package at least v1.7 forclip=TRUE
.- ltxsparklines.na.rm
Whether to delete
NA
lines from the sparkline data (TRUE
).- ltxsparklines.bottomline
Whether to add the bottom line (FALSE). You need LaTeX
sparklines
package at least v1.6 to draw bottom line.- ltxsparklines.bottomlinex
The dimensions of the extended bottom line (by default
c(NA, NA)
, which means no extended bottom line). You need LaTeXsparklines
package at least v1.7 to draw extended bottom line.- ltxsparklines.startdotcolor
The color of the dot at the start of the sparkline. If
NA
(the default), do not draw the dot.- ltxsparklines.enddotcolor
The color of the dot at the end of the sparkline. If
NA
(the default), do not draw the dot.- ltxsparklines.dotcolor
The color of dots in the sparkline (
blue
).- ltxsparklines.output
The output format (
knitr
).
Author(s)
Boris Veytsman
Maintainer: <borisv@lk.net>
References
Andreas Loeffer and Dan Luecking, Sparklines, 2016, http://www.ctan.org/pkg/sparklines
See Also
sparkline
vignette(ltxsparklines)
Examples
## Not run:
sparkline(x=c(1,3,6),
y=c(5,8,9),
startdotcolor='blue',
enddotcolor='red')
## End(Not run)
## Not run:
sparkline(Nile)
## End(Not run)
Create a Sparkline
Description
The function creates a TeX expression for a sparkline from the data supplied.
Usage
sparkline(x = NULL, y = NULL, xspikes = NULL, yspikes = NULL,
xdots = NULL, ydots = NULL, dotcolor = NULL,
width = getOption("ltxsparklines.width"),
rectangle = c(NA, NA),
xlim = c(NA, NA), ylim = c(NA, NA),
clip = getOption("ltxsparklines.clip"),
na.rm = getOption("ltxsparklines.na.rm"),
bottomline = getOption("ltxsparklines.bottomline"),
bottomlinelength = NA,
bottomlinex = getOption("ltxsparklines.bottomlinex"),
startdotcolor = getOption("ltxsparklines.startdotcolor"),
enddotcolor = getOption("ltxsparklines.enddotcolor"),
output = getOption('ltxsparklines.output'))
Arguments
x |
The data for sparkline. If both
|
y |
See |
xspikes |
The data for spikes: small bar chart similar to sparklines. If both
|
yspikes |
See |
xdots |
The data for dots: small dot chart similar to sparklines. If both
|
ydots |
See |
dotcolor |
The color of dots as a LaTeX color. A vector like
If it is not set, and data do not provide it,
|
width |
The width of the sparline in |
rectangle |
A vector |
xlim |
A vector |
ylim |
A vector |
clip |
Whether to clip the sparkline to the drawing region. The default is
not clipping. To change the default, use
|
na.rm |
Whether to delete This parameter does not affect spikes or dots. |
bottomline |
Whether to draw a bottom line. By default, |
bottomlinelength |
The length of bottom line. If |
bottomlinex |
The dimensions of the extended bottom line.
If |
startdotcolor |
The color of the dot at the beginning of the spark line. If
|
enddotcolor |
The color of the dot at the end of the spark line. If
|
output |
The format of the output. |
Details
Most of the parameters of the sparkline are defined by the TeX code. Thus all color values must be understandable to LaTeX. For example, you can put in the TeX file
\definecolor{startdot}{named}{red}
and then use it like sparkline(Nile, startdotcolor="startdot")
.
You should use LaTeX command to change sparkline parameters, for example,
\setlength\sparklinethickness{0.3pt}
The output of sparkline
is also a TeX command, so you want to
put it inside Sexpr
or a code chunk. Note that Sweave
use a special processing for Sexpr
, so you need to set
output="inlineSweave"
for inline Sweave
output. Use
output="knitr"
for knitr
(both inline and chunks) and
Sweave
chunks.
The parameters xlim
and ylim
define the mapping between
the data and the sparkline rectangle. If there are data points
outside the rectangle, they may overplot the text. You may set
clip
to TRUE
to prevent this.
Value
The function returns a string executable by TeX, to be used in
\Sexpr
, for example
Nile level changed over the years: \Sexpr{sparkline(Nile)}
.
Do not forget to add \usepackage{sparklines}
to the preamble
of your TeX document.
Author(s)
Boris Veytsman
See Also
ltxsparklines-package
,
vignette{ltxsparklines}
Examples
## Not run:
sparkline(x=c(1,3,6),
y=c(5,8,9),
startdotcolor="blue",
enddotcolor="red")
## End(Not run)
## Not run:
sparkline(Nile)
## End(Not run)