sparklines: Add Sparklines to a Figure

Description Usage Arguments Details Value See Also Examples

View source: R/sparklines.R

Description

Adds lines and (optionally) axes positioned relative to reference coordinates and scaled to the size of a character

Usage

1
2
3
4
sparklines(x, y, x_pt, y_pt, y_align = c("bot", "top", "mid", "left",
  "right"), x_align = c("left", "right", "mid"), scale_xy = TRUE,
  x_cex = 1, y_cex = 1, ax_sides = NULL, col = "black", lwd = 1,
  acol = "black", awd = 1)

Arguments

x, y

numeric vector of values for sparklines

x_pt, y_pt

numeric length 1 indicating coordinate to use as a reference for positioning sparkline

y_align

character indicating the portion of y to use for vertical alignment relative to reference coordinate

x_align

same as y_align, except for x and horizontal alignment; fewer options than y_align

scale_xy

Logical; if TRUE (default) x and y are rescaled to be the size of a character

x_cex, y_cex

numeric, scaling factor to adjust the size of the sparklines in either direction; does nothing if scale_xy is FALSE

ax_sides

Integer value(s) in 1:4 indicating the sides of the sparkline to be bordered by a solid 'axis' line; if NULL (default), no lines are drawn

col

color of the sparkline

lwd

width of the sparkline

acol

color of the axis lines

awd

width of the axis lines

Details

Created as a way of associating a mini time series with a particular point in a primary time series. For example, if plotting monthly averages, could add a sparkline for each month showing daily values.

Value

Returns NULL invisibly

See Also

For another approach to adding miniaturized time series data to a specific location on a figure, see polarGlyph.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# fake data
x <- 1:20
y <- cumsum(rnorm(20))

# plot squared values
# to show that sparkline x-y 
# can be on a different scale
plot(x^2, y^2, type='l')

# add sparklines
# showing a mini version of the time series
# leading into and out of each point
# of the big time series
for(i in 1:length(x)){
	xpt <- x[i]^2
	ypt <- y[i]^2
	sparklines(
		x, y, xpt, ypt,
		y_align="right", x_align="right", ax_sides=c(1,2), col="red", awd=0.5
	)
	sparklines(
		x, y, xpt, ypt,
		y_align="left", x_align="left", ax_sides=c(1,4), col="blue", awd=0.5
	)
}

rBatt/rbLib documentation built on May 26, 2019, 7:45 p.m.