Sparkline: Sparkline charts

View source: R/sparkline.R

SparklineR Documentation

Sparkline charts

Description

Create small charts for displaying inline with text

Usage

Sparkline(
  x,
  type = c("Area", "Line", "Curve", "Column", "Box")[1],
  fill.color = "red",
  fill.opacity = 0.5,
  line.thickness = 3,
  line.color = fill.color,
  line.opacity = 1,
  global.font.family = "Arial",
  global.font.color = rgb(44, 44, 44, maxColorValue = 255),
  font.unit = "px",
  end.points.show = FALSE,
  end.points.symbol = "circle",
  end.points.size = 20,
  end.points.color = fill.color,
  end.points.opacity = 1,
  end.labels.position = c("None", "Above", "Below", "Next")[1],
  end.labels.font.family = global.font.family,
  end.labels.font.color = global.font.color,
  end.labels.font.size = 10,
  end.labels.format = "",
  end.labels.prefix = "",
  end.labels.suffix = "",
  hover.bg.color = rgb(0.5, 0.5, 0.5),
  hover.font.family = global.font.family,
  hover.font.color = rgb(1, 1, 1),
  hover.font.size = 11,
  hover.format = "",
  background.fill.color = "transparent",
  background.fill.opacity = 1,
  x.axis.show = FALSE,
  x.axis.color = rgb(44, 44, 44, maxColorValue = 255),
  x.axis.width = 1,
  x.tick.show = x.axis.show,
  x.tick.length = 3,
  x.tick.color = x.axis.color,
  x.tick.font.family = global.font.family,
  x.tick.font.color = global.font.color,
  x.tick.font.size = 10,
  x.tick.format = "",
  y.axis.show = FALSE,
  y.axis.color = rgb(44, 44, 44, maxColorValue = 255),
  y.axis.width = 1,
  y.tick.show = y.axis.show,
  y.tick.length = 3,
  y.tick.color = y.axis.color,
  y.tick.font.family = global.font.family,
  y.tick.font.color = global.font.color,
  y.tick.font.size = 10,
  y.tick.format = "",
  margin.left = 0,
  margin.right = 0,
  margin.top = 0,
  margin.bottom = 0
)

Arguments

x

A numeric input vector to plot. Note that because sparklines is designed to be minimal there is no support for vector names, and the x-axis of these charts is always the numeric index.

type

The chart output type. One of 'Area', 'Line' (straight lines connecting points), 'Curve', 'Column' or 'Box'.

fill.color

Character; Color of chart

fill.opacity

Opacity of fill.color as an alpha value (0 to 1).

line.thickness

Thickness of line (in pixels) for Area, Line or Curve chart.

line.color

Character; Line color in Area, Line and Curve chart. For a line or curve chart, setting either fill.color or line.color while retaining default values can be used. but if both arguments are used, then fill.color will be ignored in favour of line.color.

line.opacity

Opacity of line.color as an alpha value (0 to 1).

global.font.family

Character; font family for all occurrences of any font attribute for the chart unless specified individually.

global.font.color

Global font color as a named color in character format (e.g. "black") or an a hex code.

font.unit

Set to 'pt' (default) to get font sizing consistent with textboxes. Otherwise fonts will be taken to be specified in pixels.

end.points.show

Logical; whether to show markers at either end of the series. This only applies for charts with type "Area", "Line", or "Curve".

end.points.symbol

Character; marker symbol used at end points. See https://plot.ly/r/reference/#scatter-marker-symbol for options.

end.points.size

Numeric; marker size in pixels.

end.points.color

Character; color of end point markers.

end.points.opacity

Opacity of end.points.color as an alpha value (0 to 1).

end.labels.position

Character; Whether to put labels above, below or next to end points.

end.labels.font.family

Character; label font family

end.labels.font.color

label font color as a named color in character format (e.g. "black") or an a hex code.

end.labels.font.size

Integer; label font size

end.labels.format

A string representing a d3 formatting code. See https://github.com/d3/d3/blob/master/API.md#number-formats-d3-format

end.labels.prefix

Optional text to prepend to end labels.

end.labels.suffix

Optional text to append to end labels.

hover.bg.color

Color of the background text box showing the hover text.

hover.font.family

Character; hover text font family

hover.font.color

hover text font color as a named color in character format (e.g. "black") or an a hex code.

hover.font.size

Integer; hover text font size.

hover.format

A string representing a d3 formatting code. See https://github.com/d3/d3/blob/master/API.md#number-formats-d3-format

background.fill.color

Background color in character format (e.g. "black") or a hex code.

background.fill.opacity

Background opacity as an alpha value (0 to 1).

x.axis.show

Logical; Whether to show the x-axis.

x.axis.color

Character; Color of the x-axis line.

x.axis.width

Integer; Width of the x-axis line in pixels.

x.tick.show

Logical; Whether to show ticklabels. This only has an effect is x.axis.show is true.

x.tick.length

Numeric; length of tick marks if x.axis.show.

x.tick.color

Color of tick marks on x-axis.

x.tick.font.family

Character; x-axis tick label font family

x.tick.font.color

x-axis tick label font color as a named color in character format (e.g. "black") or an a hex code.

x.tick.font.size

Integer; x-axis tick label font size

x.tick.format

A string representing a d3 formatting code. See https://github.com/d3/d3/blob/master/API.md#number-formats-d3-format

y.axis.show

Logical; Whether to show the y-axis.

y.axis.color

Character; Color of the y-axis line.

y.axis.width

Integer; Width of the y-axis line in pixels.

y.tick.show

Logical; Whether to show ticklabels. This only has an effect is y.tick.show is true.

y.tick.length

Numeric; length of tick marks if y.tick.show.

y.tick.color

Color of tick marks on y-axis

y.tick.font.family

Character; y-axis tick label font family

y.tick.font.color

y-axis tick label font color as a named color in character format (e.g. "black") or an a hex code.

y.tick.font.size

Integer; y-axis tick label font size

y.tick.format

A string representing a d3 formatting code. See https://github.com/d3/d3/blob/master/API.md#number-formats-d3-format

margin.left

Margin between plot area and the left of the graphic in pixels

margin.right

Margin between plot area and the right of the graphic in pixels

margin.top

Margin between plot area and the top of the graphic in pixels

margin.bottom

Margin between plot area and the bottom of the graphic in pixels

Examples

xx <- rnorm(10)
Sparkline(xx, background.fill.color = "black", background.fill.opacity = 1)
Sparkline(xx, type = "Curve", end.points.show = TRUE, end.labels.position = "Next",
     end.labels.format = ".1%")
Sparkline(xx, type = "Line", x.axis.show = TRUE, y.axis.show = TRUE,
     x.tick.show = FALSE, y.tick.show = FALSE)

Displayr/flipStandardCharts documentation built on Feb. 26, 2024, 12:42 a.m.