sparkline {ltxsparklines} | R Documentation |
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)