type_rug: Add a rug to a plot

View source: R/type_rug.R

type_rugR Documentation

Add a rug to a plot

Description

Adds a rug representation (1-d plot) of the data to the plot.

Usage

type_rug(
  ticksize = 0.03,
  side = 1,
  quiet = getOption("warn") < 0,
  jitter = FALSE,
  amount = NULL
)

Arguments

ticksize

The length of the ticks making up the ‘rug’. Positive lengths give inwards ticks.

side

On which side of the plot box the rug will be plotted. Normally 1 (bottom) or 3 (top).

quiet

logical indicating if there should be a warning about clipped values.

jitter

Logical. Add jittering to separate ties? Default is FALSE.

amount

Numeric. Amount of jittering (see jitter). Only used if jitter is TRUE.

Details

This function should only be used as part of tinyplot_add(), i.e. adding to an existing plot.

In most cases, determining which variable receives the rug representation will be based on the side argument (i.e., x-variable if side is 1 or 3, and y-variable if side is 2 or 4). An exception is if the preceding plot type was either "density" or "histogram"; for these latter cases, the x-variable will always be used. See Examples.

Examples

tinyplot(~wt | am, data = mtcars, type = "density", facet = "by", fill = "by")
tinyplot_add(type = "rug")
# use type_rug() to pass extra options
tinyplot_add(type = type_rug(side = 3, ticksize = 0.05))

# For ties, use jittering
tinyplot(eruptions ~ waiting, data = faithful, type = "lm")
tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.3))
tinyplot_add(type = type_rug(jitter = TRUE, amount = 0.1, side = 2))
# Add original points just for reference
tinyplot_add(type = "p")


tinyplot documentation built on April 12, 2025, 9:15 a.m.