Title: | 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). |
Authors: | Boris Veytsman [aut, cre] |
Maintainer: | Boris Veytsman <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 1.1.3 |
Built: | 2024-11-19 05:10:46 UTC |
Source: | https://github.com/borisveytsman/ltxsparklines |
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).
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 = "[email protected]")) |
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 |
Repository: | https://borisveytsman.r-universe.dev |
RemoteUrl: | https://github.com/borisveytsman/ltxsparklines |
RemoteRef: | HEAD |
RemoteSha: | 5e60caabbe7ea37e570eda146841f94a5f5b2404 |
Author: | Boris Veytsman [aut, cre] |
Maintainer: | Boris Veytsman <[email protected]> |
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).
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)
.
The width of the sparkline
(10
).
Whether to clip the sparklines in the
drawing region (FALSE
). You need LaTeX sparklines
package at least v1.7 for clip=TRUE
.
Whether to delete NA
lines from
the sparkline data (TRUE
).
Whether to add the bottom line
(FALSE). You need LaTeX
sparklines
package at least v1.6 to draw bottom
line.
The dimensions of the extended
bottom line (by default c(NA, NA)
, which means no extended
bottom line). You need LaTeX
sparklines
package at least v1.7 to draw extended bottom
line.
The color of the dot at the start
of the sparkline. If NA
(the default), do not draw the dot.
The color of the dot at the end
of the sparkline. If NA
(the default), do not draw the dot.
The color of dots in the sparkline
(blue
).
The output format (knitr
).
Boris Veytsman
Maintainer: <[email protected]>
Andreas Loeffer and Dan Luecking, Sparklines, 2016, http://www.ctan.org/pkg/sparklines
sparkline
vignette(ltxsparklines)
## 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)
## 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)
The function creates a TeX expression for a sparkline from the data supplied.
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'))
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'))
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. |
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.
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.
Boris Veytsman
ltxsparklines-package
,
vignette{ltxsparklines}
## 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)
## 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)